{"version":3,"file":"search.slice-M9Xdsd2N.js","sources":["../../../../../../../../app/frontend/entities/search/models/search.slice.ts"],"sourcesContent":["import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'\nimport type { PayloadAction } from '@reduxjs/toolkit'\nimport { AxiosResponse } from 'axios'\n\nimport { REGISTRATION_ERROR_MSG } from '~/entities/profile/lib/consts'\nimport searchApi from '~/shared/api/search.api'\nimport { RegionsType } from '~/shared/types/regions'\nimport { HighlightType } from '~/shared/types/zamanuha'\n\nimport { defineErrorMessage } from './utils'\n\n// TODO: move types into a separate file\nexport type ReportType = {\n type: 'reportPremium'\n apartYield: number\n apartSaleCount: number\n apartRentCount: number\n apartAvgSalePrice: number\n apartAvgRentPrice: number\n apartBedroom1Yield: number\n apartBedroom1SaleCount: number\n apartBedroom1RentCount: number\n apartBedroom1AvgSalePrice: number\n apartBedroom1AvgRentPrice: number\n apartBedroom2Yield: number\n apartBedroom2SaleCount: number\n apartBedroom2RentCount: number\n apartBedroom2AvgSalePrice: number\n apartBedroom2AvgRentPrice: number\n apartBedroom3Yield: number\n apartBedroom3SaleCount: number\n apartBedroom3RentCount: number\n apartBedroom3AvgSalePrice: number\n apartBedroom3AvgRentPrice: number\n apartBedroomGte4Yield: number\n apartBedroomGte4SaleCount: number\n apartBedroomGte4RentCount: number\n apartBedroomGte4AvgSalePrice: number\n apartBedroomGte4AvgRentPrice: number\n houseYield: number\n houseSaleCount: number\n houseRentCount: number\n houseAvgSalePrice: string\n houseAvgRentPrice: string\n houseAreaLt40Yield: number | null\n houseAreaLt40SaleCount: number\n houseAreaLt40RentCount: number\n houseAreaLt40AvgSalePrice: string | null\n houseAreaLt40AvgRentPrice: string | null\n houseAreaGte40Lt70Yield: number\n houseAreaGte40Lt70SaleCount: number\n houseAreaGte40Lt70RentCount: number\n houseAreaGte40Lt70AvgSalePrice: string\n houseAreaGte40Lt70AvgRentPrice: string\n houseAreaGte70Yield: number\n houseAreaGte70SaleCount: number\n houseAreaGte70RentCount: number\n houseAreaGte70AvgSalePrice: string\n houseAreaGte70AvgRentPrice: string\n}\n\n// TODO: fix that\nexport const enum ReportTypes {\n // eslint-disable-next-line no-unused-vars\n premium = 'reportPremium',\n // eslint-disable-next-line no-unused-vars\n free = 'reportFree',\n // eslint-disable-next-line no-unused-vars\n hidden = 'reportHidden',\n}\n\nexport type ReportFiltersType = {\n avgRentPrice: number\n avgSalePrice: number\n key: string\n reliabilityScore: number\n rentCount: number\n saleCount: number\n yield: number\n}\n\n// TODO: it should be renamed modified with non-premium report\nexport type ReportPremium = {\n type: ReportTypes\n currency: {\n code: string\n symbol: string\n }\n filters: ReportFiltersType[]\n apartYield?: number\n apartSaleCount?: number\n apartRentCount?: number\n apartAvgSalePrice?: number\n apartAvgRentPrice?: number\n apartBedroom0Yield?: number\n apartBedroom0SaleCount?: number\n apartBedroom0RentCount?: number\n apartBedroom0AvgSalePrice?: number\n apartBedroom0AvgRentPrice?: number\n apartBedroom1Yield?: number\n apartBedroom1SaleCount?: number\n apartBedroom1RentCount?: number\n apartBedroom1AvgSalePrice?: number\n apartBedroom1AvgRentPrice?: number\n apartBedroom2Yield?: number\n apartBedroom2SaleCount?: number\n apartBedroom2RentCount?: number\n apartBedroom2AvgSalePrice?: number\n apartBedroom2AvgRentPrice?: number\n apartBedroom3Yield?: number\n apartBedroom3SaleCount?: number\n apartBedroom3RentCount?: number\n apartBedroom3AvgSalePrice?: number\n apartBedroom3AvgRentPrice?: number\n apartBedroomGte4Yield?: number\n apartBedroomGte4SaleCount?: number\n apartBedroomGte4RentCount?: number\n apartBedroomGte4AvgSalePrice?: number\n apartBedroomGte4AvgRentPrice?: number\n houseYield?: number\n houseSaleCount?: number\n houseRentCount?: number\n houseAvgSalePrice?: number\n houseAvgRentPrice?: number\n houseAreaLt100Yield?: number\n houseAreaLt100SaleCount?: number\n houseAreaLt100RentCount?: number\n houseAreaLt100AvgSalePrice?: number\n houseAreaLt100AvgRentPrice?: number\n houseAreaGte100Lt200Yield?: number\n houseAreaGte100Lt200SaleCount?: number\n houseAreaGte100Lt200RentCount?: number\n houseAreaGte100Lt200AvgSalePrice?: number\n houseAreaGte100Lt200AvgRentPrice?: number\n houseAreaGte200Lt300Yield?: number\n houseAreaGte200Lt300SaleCount?: number\n houseAreaGte200Lt300RentCount?: number\n houseAreaGte200Lt300AvgSalePrice?: number\n houseAreaGte200Lt300AvgRentPrice?: number\n houseAreaGte300Yield?: number\n houseAreaGte300SaleCount?: number\n houseAreaGte300RentCount?: number\n houseAreaGte300AvgSalePrice?: number\n houseAreaGte300AvgRentPrice?: number\n}\n\nexport type DistrictType = {\n type: string\n publicId: string\n name: string\n fullName: string\n countryCode: string\n polygonsEncoded?: string[]\n report: ReportPremium\n}\n\ntype CurrencyType = {\n code: string\n symbol: string\n}\n\nexport type MainPackageType = {\n cityCount: number\n countryCode: RegionsType\n districtCount: number\n id: string\n listingCount: number\n maxYield: number\n minYield: number\n name: string\n oldPriceAmount?: number\n priceAmount: number\n priceCurrency: CurrencyType\n subDistrictCount: number\n}\n\nexport type TopDistrictType = DistrictType & {\n subDistricts: DistrictType[]\n}\n\nexport type CityType = {\n countryCode: string\n polygonsEncoded?: string[]\n report: ReportPremium\n type: string\n publicId: string\n name: string\n fullName: string\n}\n\nexport type LocationDetailsType = {\n location: {\n type: string\n publicId: string\n name: string\n fullName: string\n countryCode: string // todo: override to exact strings\n polygonsEncoded?: string[]\n score?: number\n report: ReportPremium\n region: {\n type: string\n publicId: string\n name: string\n fullName: string\n countryCode: string\n polygonsEncoded: string[]\n }\n highlight: HighlightType\n topDistricts?: TopDistrictType[]\n cities?: CityType[]\n mainPackage?: MainPackageType\n }\n}\n\nexport type LocationItem = {\n countryCode: string\n name: string\n publicId: string\n region: {\n name: string\n publicId: string\n }\n type: string\n polygonsEncoded: string[]\n}\n\nexport type ResponseStatus = {\n locations: LocationItem[]\n}\n\nexport type TypeFilterType =\n | 'houseYield'\n | 'apartYield'\n | 'apartBedroom0Yield'\n | 'apartBedroom1Yield'\n | 'apartBedroom2Yield'\n | 'apartBedroom3Yield'\n | 'apartBedroomGte4Yield'\n | 'houseAreaLt100Yield'\n | 'houseAreaGte100Lt200Yield'\n | 'houseAreaGte200Lt300Yield'\n | 'houseAreaGte300Yield'\nexport type FiltersType = {\n type: {\n value: TypeFilterType\n }\n}\ntype RootRegionType = DistrictType & Partial<{ mainPackage?: Partial }>\n\nexport type SearchSliceType = {\n results: LocationItem[]\n searchRef?: HTMLInputElement\n errorMessage: string\n isLoading: boolean\n isModalVisible: boolean\n selectedId?: string | number\n rootRegion?: RootRegionType\n selectedCountry?: RegionsType\n selectedRegion: {\n name?: string\n filters: FiltersType\n publicId?: string\n polygons?: string[]\n childRegions?: TopDistrictType[] | DistrictType[]\n subDistrictOpenedId?: string\n type?: string\n }\n // modalDetails?: LocationDetailsType\n}\n\nexport type SearchRequestType = {\n country: string\n term: string\n}\n\nconst initialState: SearchSliceType = {\n isLoading: false,\n searchRef: null,\n errorMessage: '',\n results: [],\n isModalVisible: false,\n rootRegion: undefined,\n selectedCountry: undefined,\n selectedRegion: {\n publicId: '',\n filters: {\n type: {\n value: 'apartYield',\n },\n },\n },\n}\n\nexport const search = createAsyncThunk(\n 'search/term',\n async (data: { country: string; term: string }) => {\n const response = await searchApi.search(data.country, data.term)\n return { res: response, term: data.term }\n }\n)\n\nexport const searchLocations = createAsyncThunk('search/locations', async (id: string | number) => {\n const response = await searchApi.searchLocations(id)\n return response\n})\n\nexport const profileSlice = createSlice({\n name: 'search',\n initialState,\n reducers: {\n toggleModal(state) {\n state.isModalVisible = !state.isModalVisible\n },\n setSelectedCountry(state, action: PayloadAction) {\n state.selectedCountry = action.payload\n },\n setSelectedId(state, action: PayloadAction) {\n state.selectedId = action.payload\n },\n // LocationDetailsType\n selectSubDistrict(state, action: PayloadAction) {\n state.selectedRegion.subDistrictOpenedId = action.payload\n },\n setSearchRef: (state, action) => {\n state.searchRef = action.payload\n },\n setFilters(\n state,\n action: PayloadAction<{\n key: 'type'\n value: TypeFilterType\n }>\n ) {\n state.selectedRegion.filters[action.payload.key].value = action.payload.value\n },\n selectRootRegion(state, action: PayloadAction) {\n state.rootRegion = {\n ...action.payload,\n }\n },\n selectLocationDetails(\n state,\n action: PayloadAction<{\n childRegions: DistrictType[]\n polygonsEncoded: string[]\n publicId: string\n type: string\n name?: string\n subDistrictOpenedId?: string\n }>\n ) {\n state.selectedRegion.childRegions = action.payload.childRegions\n state.selectedRegion.name = action.payload.name\n state.selectedRegion.polygons = action.payload.polygonsEncoded\n state.selectedRegion.publicId = action.payload.publicId\n state.selectedRegion.type = action.payload.type\n if (action.payload.subDistrictOpenedId) {\n state.selectedRegion.subDistrictOpenedId = action.payload.subDistrictOpenedId\n }\n },\n forceRefreshSearch(state) {\n state.errorMessage = ''\n state.results = []\n },\n },\n extraReducers: (builder) => {\n // TODO: rewrite axios w ts\n builder.addCase(\n search.fulfilled,\n (state, action: PayloadAction<{ res: AxiosResponse; term: string }>) => {\n state.isLoading = false\n if (action.payload.res.status === 200) {\n state.results = action.payload.res.data?.locations ?? []\n state.errorMessage = defineErrorMessage(action.payload.term, 'No Locations found')\n } else {\n state.results = []\n state.errorMessage = defineErrorMessage(action.payload.term, 'No Locations found')\n }\n }\n )\n builder.addCase(search.pending, (state) => {\n state.isLoading = true\n state.errorMessage = ''\n })\n builder.addCase(search.rejected, (state) => {\n state.isLoading = false\n state.errorMessage = REGISTRATION_ERROR_MSG\n })\n // TODO: separate\n builder.addCase(searchLocations.rejected, (state) => {\n state.isLoading = false\n })\n builder.addCase(searchLocations.fulfilled, (state) => {\n state.isLoading = false\n })\n builder.addCase(searchLocations.pending, (state) => {\n state.isLoading = true\n })\n },\n})\n\nexport const {\n selectSubDistrict,\n setFilters,\n toggleModal,\n setSelectedId,\n selectLocationDetails,\n selectRootRegion,\n forceRefreshSearch,\n setSelectedCountry,\n setSearchRef,\n} = profileSlice.actions\n\nexport default profileSlice.reducer\n"],"names":["ReportTypes","initialState","search","createAsyncThunk","data","searchApi","searchLocations","id","profileSlice","createSlice","state","action","builder","_a","defineErrorMessage","REGISTRATION_ERROR_MSG","selectSubDistrict","setFilters","toggleModal","setSelectedId","selectLocationDetails","selectRootRegion","forceRefreshSearch","setSelectedCountry","setSearchRef","search$1"],"mappings":"6NA8DkB,IAAAA,GAAAA,IAEhBA,EAAA,QAAU,gBAEVA,EAAA,KAAO,aAEPA,EAAA,OAAS,eANOA,IAAAA,GAAA,CAAA,CAAA,EAsNlB,MAAMC,EAAgC,CACpC,UAAW,GACX,UAAW,KACX,aAAc,GACd,QAAS,CAAC,EACV,eAAgB,GAChB,WAAY,OACZ,gBAAiB,OACjB,eAAgB,CACd,SAAU,GACV,QAAS,CACP,KAAM,CACJ,MAAO,YACT,CACF,CACF,CACF,EAEaC,EAASC,EACpB,cACA,MAAOC,IAEE,CAAE,IADQ,MAAMC,EAAU,OAAOD,EAAK,QAASA,EAAK,IAAI,EACvC,KAAMA,EAAK,IAAK,EAE5C,EAEaE,EAAkBH,EAAiB,mBAAoB,MAAOI,GACxD,MAAMF,EAAU,gBAAgBE,CAAE,CAEpD,EAEYC,EAAeC,EAAY,CACtC,KAAM,SACN,aAAAR,EACA,SAAU,CACR,YAAYS,EAAO,CACXA,EAAA,eAAiB,CAACA,EAAM,cAChC,EACA,mBAAmBA,EAAOC,EAAoC,CAC5DD,EAAM,gBAAkBC,EAAO,OACjC,EACA,cAAcD,EAAOC,EAAwC,CAC3DD,EAAM,WAAaC,EAAO,OAC5B,EAEA,kBAAkBD,EAAOC,EAA+B,CAChDD,EAAA,eAAe,oBAAsBC,EAAO,OACpD,EACA,aAAc,CAACD,EAAOC,IAAW,CAC/BD,EAAM,UAAYC,EAAO,OAC3B,EACA,WACED,EACAC,EAIA,CACMD,EAAA,eAAe,QAAQC,EAAO,QAAQ,GAAG,EAAE,MAAQA,EAAO,QAAQ,KAC1E,EACA,iBAAiBD,EAAOC,EAAuC,CAC7DD,EAAM,WAAa,CACjB,GAAGC,EAAO,OAAA,CAEd,EACA,sBACED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