-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e52b597
commit 02d3466
Showing
12 changed files
with
334 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
frontend/src/components/CostumerTable/ActiveCustomerFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
import { useContext } from "react"; | ||
import { FilteredCustomerContext } from "@/hooks/CustomerFilterProvider"; | ||
|
||
export default function ActiveCustomerFilters() { | ||
const filterTextComponents: string[] = []; | ||
const { activeFilters } = useContext(FilteredCustomerContext); | ||
|
||
const { searchFilter, engagementIsBillableFilter, bookingTypeFilter } = | ||
activeFilters; | ||
|
||
if (searchFilter != "") filterTextComponents.push(` "${searchFilter}"`); | ||
if (engagementIsBillableFilter != "") filterTextComponents.push(`engagement`); | ||
if (bookingTypeFilter != "") | ||
filterTextComponents.push(` "${bookingTypeFilter}"`); | ||
|
||
const filterSummaryText = filterTextComponents.join(", "); | ||
|
||
return ( | ||
<div className="h-4"> | ||
{filterSummaryText != "" && ( | ||
<p className="small-medium text-primary"> {filterSummaryText} </p> | ||
)} | ||
</div> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
frontend/src/components/CostumerTable/CustomerSidebarWithFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FilteredCustomerContext } from "@/hooks/CustomerFilterProvider"; | ||
import SearchBarComponent from "../SearchBarComponent"; | ||
|
||
export default function CustomerSidebarWithFilters() { | ||
return ( | ||
<> | ||
<div className="sidebar z-10 bg-background_grey h-full flex flex-col gap-6 p-4 w-[300px] overflow-y-auto"> | ||
<div className="flex flex-row justify-between items-center"> | ||
<h1 className="">Filter</h1> | ||
</div> | ||
<SearchBarComponent context={FilteredCustomerContext} /> | ||
</div> | ||
</> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
frontend/src/components/CostumerTable/FilteredCustomersTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
import { EngagementPerCustomerReadModel } from "@/api-types"; | ||
import CustomerRow from "@/components/CostumerTable/CustomerRow"; | ||
import { useCustomerFilter } from "@/hooks/staffing/useCustomerFilter"; | ||
|
||
function FilteredCustomerTable() { | ||
const filteredCustomers = useCustomerFilter(); | ||
|
||
return ( | ||
<table className="w-full min-w-[700px] table-fixed"> | ||
<colgroup> | ||
<col span={1} className="w-16" /> | ||
<col span={1} className="w-[300px]" /> | ||
{[1].map((_, index) => ( | ||
<col key={index} span={1} /> | ||
))} | ||
</colgroup> | ||
<thead> | ||
<tr> | ||
<th colSpan={2}> | ||
<div className="flex flex-row gap-3 pb-4 items-center"> | ||
<p className="normal-medium ">Kunder</p> | ||
<p className="text-primary small-medium rounded-full bg-secondary/30 px-2 py-1"> | ||
{filteredCustomers?.length} | ||
</p> | ||
</div> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{filteredCustomers.map((customer: EngagementPerCustomerReadModel) => ( | ||
<CustomerRow key={customer.customerId} customer={customer} /> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
|
||
export { FilteredCustomerTable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"use client"; | ||
|
||
import { EngagementPerCustomerReadModel, EngagementState } from "@/api-types"; | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { createContext, ReactNode, useEffect, useState } from "react"; | ||
|
||
export type CustomerFilters = { | ||
searchFilter: string; | ||
engagementIsBillableFilter: boolean | string; | ||
bookingTypeFilter: EngagementState | string; | ||
}; | ||
|
||
interface UpdateFilterParams { | ||
search?: string; | ||
engagementIsBillable?: boolean; | ||
bookingType?: EngagementState; | ||
} | ||
export type UpdateFilters = (updateParams: UpdateFilterParams) => void; | ||
const defaultFilters: CustomerFilters = { | ||
searchFilter: "", | ||
engagementIsBillableFilter: "", | ||
bookingTypeFilter: "", | ||
}; | ||
|
||
type CustomerFilterContextType = { | ||
activeFilters: CustomerFilters; | ||
updateFilters: UpdateFilters; | ||
customers: EngagementPerCustomerReadModel[]; | ||
setCustomers: React.Dispatch< | ||
React.SetStateAction<EngagementPerCustomerReadModel[]> | ||
>; | ||
}; | ||
|
||
export const FilteredCustomerContext = createContext<CustomerFilterContextType>( | ||
{ | ||
customers: [], | ||
setCustomers: () => null, | ||
activeFilters: defaultFilters, | ||
updateFilters: () => null, | ||
}, | ||
); | ||
|
||
export function CustomerFilterProvider(props: { | ||
customers: EngagementPerCustomerReadModel[]; | ||
children: ReactNode; | ||
}) { | ||
const [customers, setCustomers] = useState<EngagementPerCustomerReadModel[]>( | ||
[], | ||
); | ||
const [activeFilters, updateFilters] = useUrlRouteFilter(); | ||
|
||
useEffect(() => setCustomers(props.customers), [props.customers]); | ||
|
||
return ( | ||
<FilteredCustomerContext.Provider | ||
value={{ | ||
...props, | ||
customers, | ||
setCustomers, | ||
activeFilters, | ||
updateFilters, | ||
}} | ||
> | ||
{props.children} | ||
</FilteredCustomerContext.Provider> | ||
); | ||
} | ||
|
||
function useUrlRouteFilter(): [CustomerFilters, UpdateFilters] { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
|
||
const [searchFilter, setSearchFilter] = useState( | ||
searchParams.get("search") || "", | ||
); | ||
const [engagementIsBillableFilter, setEngagementIsBillableFilter] = useState( | ||
searchParams.get("engagementIsBillable") || false, | ||
); | ||
const [bookingTypeFilter, setBookingTypeFilter] = useState( | ||
searchParams.get("bookingType") || "", | ||
); | ||
|
||
function updateRoute(updateParams: UpdateFilterParams) { | ||
// If not defined, defaults to current value: | ||
const { search = searchFilter } = updateParams; | ||
const { engagementIsBillable = engagementIsBillableFilter } = updateParams; | ||
const { bookingType = bookingTypeFilter } = updateParams; | ||
|
||
const url = `${pathname}?search=${search}&engagementIsBillable=${engagementIsBillable}&bookingType=${bookingType}}`; | ||
|
||
setSearchFilter(search); | ||
setEngagementIsBillableFilter(engagementIsBillable); | ||
setBookingTypeFilter(bookingType); | ||
|
||
window.history.pushState({}, "", url); | ||
} | ||
|
||
return [ | ||
{ | ||
searchFilter, | ||
engagementIsBillableFilter, | ||
bookingTypeFilter, | ||
}, | ||
updateRoute, | ||
]; | ||
} |
Oops, something went wrong.