diff --git a/src/components/apis/default.ts b/src/components/apis/default.ts index 2d23f3d..616e3e0 100644 --- a/src/components/apis/default.ts +++ b/src/components/apis/default.ts @@ -36,12 +36,12 @@ export async function apiRequest({ method, path, body, header }: apiRequesProps) } else if (method === 'DELETE') { res = await customAxios.delete(path, body) } - console.log(res) + // console.log(res) return { status: res?.status || res?.data?.status, message: res?.data } } catch (error) { - console.log(error) + // console.log(error) if (axios.isAxiosError(error)) { - console.log(error.response?.data?.message) + // console.log(error.response?.data?.message) return { status: error?.response?.status, message: error?.response?.data?.message, diff --git a/src/components/user-dashboard/DataTable.tsx b/src/components/user-dashboard/DataTable.tsx index 75cefeb..9a31b0d 100644 --- a/src/components/user-dashboard/DataTable.tsx +++ b/src/components/user-dashboard/DataTable.tsx @@ -19,11 +19,7 @@ interface DataTableProps { } // Define the DataTable component as a functional component -export function DataTable({ - columns, - data, - queryData, -}: DataTableProps) { +export function DataTable({ columns, data }: DataTableProps) { // Initialize a table instance using useReactTable const table = useReactTable({ data, // Data to display @@ -34,7 +30,7 @@ export function DataTable({ return (
diff --git a/src/components/user-dashboard/FullScreenSearchBar.tsx b/src/components/user-dashboard/FullScreenSearchBar.tsx index 6654b1f..467f65a 100644 --- a/src/components/user-dashboard/FullScreenSearchBar.tsx +++ b/src/components/user-dashboard/FullScreenSearchBar.tsx @@ -8,6 +8,7 @@ interface FullScreenSearchBarProps { setQuery: Dispatch> // Function to update the search query fetchDataOnEnter: React.FormEventHandler queryData: object + toggle: boolean } // Create a functional component named FullScreenSearchBar and provide the expected props @@ -15,7 +16,8 @@ export const FullScreenSearchBar: FC = ({ query, setQuery, fetchDataOnEnter, - queryData, + // queryData, + toggle, }) => { // Function to handle input changes and update the query and focus state const handleInputChange = (e: React.ChangeEvent) => { @@ -26,14 +28,14 @@ export const FullScreenSearchBar: FC = ({ <>
() + const [servicesToBeUsed, setServicesTobeUsed] = useState([]) + const [serviceDataFromSearchInput, setServiceDataFromSearchInput] = + useState() + const [providerName, setProviderName] = useState('') + + const serviceDataFromSearch: TUserDashboardTable[] = useMemo(() => { + return [] + }, []) + + const regularServiceData: TUserDashboardTable[] = useMemo(() => { + return [] + }, []) + // Remove the below when unecessary -1Solon // eslint-disable-next-line @typescript-eslint/no-unused-vars const router = useRouter() const authState = useSelector(selectAuthState) + const getServiceData = async () => { + try { + const serviceData = await apiRequest({ method: METHODS.GET, path: '/services' }) + setServiceData(serviceData?.message) + } catch (err) { + console.log(err) + } + } + + const getProviderNameFromId = async (providerId: number) => { + try { + const provider = await apiRequest({ + method: METHODS.GET, + path: `/users/${String(providerId)}`, + }) + setProviderName(provider?.message?.username) + } catch (err) { + console.log(err) + } + } + + const getServicesUsingSearch = async (searchQuery: string) => { + try { + const serviceData = await apiRequest({ method: METHODS.GET, path: `/search/${searchQuery}` }) + setServiceDataFromSearchInput(serviceData) + } catch (err) { + console.log(err) + } + } + + useEffect(() => { + if (!serviceData) getServiceData() + }, [serviceData]) + + useEffect(() => { + serviceDataFromSearchInput?.message?.searchResult?.map((service: ServiceAvailability) => { + getProviderNameFromId(service.provider_id) + serviceDataFromSearch?.push({ + short_description: service?.description, + provider: providerName, + availability: service?.availability, + pricing: String(service?.pricing), + }) + }) + console.log(serviceDataFromSearch) + }, [providerName, serviceDataFromSearch, serviceDataFromSearchInput?.message?.searchResult]) + + useEffect(() => { + serviceData?.map(service => { + getProviderNameFromId(service.provider_id) + regularServiceData?.push({ + availability: service.availability, + pricing: String(service.pricing), + provider: providerName, + short_description: service.description, + }) + console.log(regularServiceData) + }) + }, [serviceData]) + + useEffect(() => { + if (serviceDataFromSearch.length === 0) setServicesTobeUsed(regularServiceData) + else setServicesTobeUsed(serviceDataFromSearch) + }, [serviceDataFromSearch, regularServiceData]) + /* Cookie-consent check & Modal */ useEffect(() => { if (JSON.stringify(consent) === '{}') { @@ -54,8 +149,7 @@ export default function Index({ consent }: IndexProps): JSX.Element { // eslint-disable-next-line @typescript-eslint/no-unused-vars const fetchDataOnEnter = (event: React.FormEvent) => { event.preventDefault() - const formData = new FormData(event.currentTarget) - setFetchedData(formData) + getServicesUsingSearch(query) } useEffect(() => { @@ -64,7 +158,7 @@ export default function Index({ consent }: IndexProps): JSX.Element { // useEffect to check user authentication and redirect if not authenticated useEffect(() => { - // if (!authState) router.push("user-login"); + // if (!authState) router.push('user-login') // eslint-disable-next-line react-hooks/exhaustive-deps }, [authState]) @@ -86,19 +180,19 @@ export default function Index({ consent }: IndexProps): JSX.Element {
- {/* */} - - {/* + */} + />