diff --git a/frontend/src/components/CustomerTable/CustomerSidebarWithFilters.tsx b/frontend/src/components/CustomerTable/CustomerSidebarWithFilters.tsx index 593dcd5c..7def8465 100644 --- a/frontend/src/components/CustomerTable/CustomerSidebarWithFilters.tsx +++ b/frontend/src/components/CustomerTable/CustomerSidebarWithFilters.tsx @@ -5,13 +5,8 @@ import { ToggleSwitch } from "./SwitchToggle"; import { useIsCustomerActive } from "@/hooks/CustomerFilter/useIsCustomerActive"; export default function CustomerSidebarWithFilters() { - const [checked, setChecked] = useState(false); - function handleChange(nextChecked: boolean) { - setChecked(nextChecked); - } - const { isCustomerActive, toggleActive } = useIsCustomerActive( - FilteredCustomerContext, - ); + const { isCustomerActive, toggleActive } = useIsCustomerActive(); + console.log("customer activa", isCustomerActive); return ( <>
diff --git a/frontend/src/components/CustomerTable/SwitchToggle.tsx b/frontend/src/components/CustomerTable/SwitchToggle.tsx index 0add1aee..3656d873 100644 --- a/frontend/src/components/CustomerTable/SwitchToggle.tsx +++ b/frontend/src/components/CustomerTable/SwitchToggle.tsx @@ -12,7 +12,7 @@ export function ToggleSwitch({ value, onChange, }: { - value: boolean; + value: boolean | string; onChange: () => any; }) { return ( diff --git a/frontend/src/hooks/CustomerFilter/CustomerFilterProvider.tsx b/frontend/src/hooks/CustomerFilter/CustomerFilterProvider.tsx index 8659cb7d..1c31fa8e 100644 --- a/frontend/src/hooks/CustomerFilter/CustomerFilterProvider.tsx +++ b/frontend/src/hooks/CustomerFilter/CustomerFilterProvider.tsx @@ -15,14 +15,14 @@ interface UpdateFilterParams { search?: string; engagementIsBillable?: boolean; bookingType?: EngagementState; - isCustomerActive: boolean; + isCustomerActive: boolean | string; } export type UpdateFilters = (updateParams: UpdateFilterParams) => void; const defaultFilters: CustomerFilters = { searchFilter: "", engagementIsBillableFilter: "", bookingTypeFilter: "", - isCustomerActiveFilter: false, + isCustomerActiveFilter: "", }; type CustomerFilterContextType = { @@ -93,7 +93,7 @@ function useUrlRouteFilter(): [CustomerFilters, UpdateFilters] { const { bookingType = bookingTypeFilter } = updateParams; const { isCustomerActive = isCustomerActiveFilter } = updateParams; - const url = `${pathname}?search=${search}&engagementIsBillable=${engagementIsBillable}&bookingType=${bookingType}}&isCustomerActive=${isCustomerActive}`; + const url = `${pathname}?search=${search}&isCustomerActive=${isCustomerActive}`; setSearchFilter(search); setEngagementIsBillableFilter(engagementIsBillable); diff --git a/frontend/src/hooks/CustomerFilter/useIsCustomerActive.ts b/frontend/src/hooks/CustomerFilter/useIsCustomerActive.ts index 518c356e..c5eff952 100644 --- a/frontend/src/hooks/CustomerFilter/useIsCustomerActive.ts +++ b/frontend/src/hooks/CustomerFilter/useIsCustomerActive.ts @@ -1,11 +1,27 @@ import { Context, useContext, useEffect, useState } from "react"; +import { FilteredCustomerContext } from "./CustomerFilterProvider"; +import { parse } from "next/dist/build/swc"; -export function useIsCustomerActive(context: Context) { - const { updateFilters, activeFilters } = useContext(context); +function parseBooleanOrString(value: string | boolean) { + if (typeof value === "string") { + if (value === "true") { + return true; + } else if (value === "false") { + return false; + } else { + return ""; // + } + } else { + return value; + } +} +export function useIsCustomerActive() { + const { updateFilters, activeFilters } = useContext(FilteredCustomerContext); const isCustomerActiveFilter = activeFilters.isCustomerActiveFilter; - - const [isCustomerActive, setIsCustomerActive] = useState( - isCustomerActiveFilter, + const parsedActive = parseBooleanOrString(isCustomerActiveFilter); + const valueForToggle = parsedActive === "" ? true : parsedActive; + const [isCustomerActive, setIsCustomerActive] = useState( + valueForToggle, ); function toggleActive() { setIsCustomerActive(!isCustomerActive);