Skip to content

Commit

Permalink
Refactor disabling parameters options
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas authored and andresgnlez committed Dec 17, 2024
1 parent 59c80b7 commit 7b4fd2e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
13 changes: 13 additions & 0 deletions client/src/app/(overview)/url-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ import { TABLE_VIEWS } from "@/containers/overview/table/toolbar/table-selector"

const SUB_ACTIVITIES = RESTORATION_ACTIVITY_SUBTYPE;

interface ParameterOption {
label: string;
value: string;
disabled?: boolean;
}

export interface Parameter {
key: keyof Omit<z.infer<typeof filtersSchema>, "keyword">;
label: string;
className: string;
options: ParameterOption[];
}

export const filtersSchema = z.object({
[FILTER_KEYS[0]]: z.string().optional(),
[FILTER_KEYS[1]]: z.nativeEnum(PROJECT_SIZE_FILTER),
Expand Down
12 changes: 6 additions & 6 deletions client/src/containers/overview/header/parameters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { z } from "zod";

import { FILTER_KEYS } from "@/app/(overview)/constants";
import { useGlobalFilters } from "@/app/(overview)/url-store";
import { Parameter, useGlobalFilters } from "@/app/(overview)/url-store";
import { filtersSchema } from "@/app/(overview)/url-store";

import { INITIAL_COST_RANGE } from "@/containers/overview/filters/constants";
Expand All @@ -19,7 +19,8 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
export const PROJECT_PARAMETERS = [

export const PROJECT_PARAMETERS: Parameter[] = [
{
key: FILTER_KEYS[1],
label: "Project size",
Expand Down Expand Up @@ -51,6 +52,7 @@ export const PROJECT_PARAMETERS = [
{
label: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE,
value: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE,
disabled: true,
},
],
},
Expand Down Expand Up @@ -94,7 +96,7 @@ export default function ParametersProjects() {
<Label htmlFor={parameter.label}>{parameter.label}</Label>
<Select
name={parameter.label}
defaultValue={filters[parameter.key]}
defaultValue={String(filters[parameter.key])}
onValueChange={(v) => {
handleParameters(v, parameter.key);
}}
Expand All @@ -107,9 +109,7 @@ export default function ParametersProjects() {
<SelectItem
key={option.value}
value={option.value}
disabled={
option.value === PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE
}
disabled={option?.disabled}
>
{option.label}
</SelectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { atom, useAtom } from "jotai";
import { z } from "zod";

import { FILTER_KEYS } from "@/app/(overview)/constants";
import { filtersSchema } from "@/app/(overview)/url-store";
import { filtersSchema, Parameter } from "@/app/(overview)/url-store";

import { Label } from "@/components/ui/label";
import {
Expand All @@ -26,7 +26,7 @@ const INITIAL_FILTERS_STATE: Partial<z.infer<typeof filtersSchema>> = {

const filtersAtom = atom(INITIAL_FILTERS_STATE);

export const PROJECT_PARAMETERS = [
export const PROJECT_PARAMETERS: Parameter[] = [
{
key: FILTER_KEYS[1],
label: "Project size",
Expand Down Expand Up @@ -58,6 +58,7 @@ export const PROJECT_PARAMETERS = [
{
label: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE,
value: PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE,
disabled: true,
},
],
},
Expand Down Expand Up @@ -99,7 +100,7 @@ export default function ParametersProjects() {
<Label htmlFor={parameter.label}>{parameter.label}</Label>
<Select
name={parameter.label}
defaultValue={filters[parameter.key]}
defaultValue={String(filters[parameter.key])}
onValueChange={(v) => {
handleParameters(v, parameter.key);
}}
Expand All @@ -112,9 +113,7 @@ export default function ParametersProjects() {
<SelectItem
key={option.value}
value={option.value}
disabled={
option.value === PROJECT_PRICE_TYPE.OPEN_BREAK_EVEN_PRICE
}
disabled={option?.disabled}
>
{option.label}
</SelectItem>
Expand Down

0 comments on commit 7b4fd2e

Please sign in to comment.