Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Nov 28, 2024
1 parent 8711eaa commit fb93261
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 352 deletions.
2 changes: 1 addition & 1 deletion client/src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";

let browserQueryClient: QueryClient | undefined = undefined;

function getQueryClient() {
export function getQueryClient() {
if (isServer) {
// Server: always make a new query client
return makeQueryClient();
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/ui/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ const RadioGroupItemBox = React.forwardRef<
RadioGroupItemBoxProps
>(({ className, checked, label, description, value, ...radioProps }, ref) => {
return (
<div
<label
className={cn(
"cursor-pointer rounded-xl border border-border p-4",
className,
{
"border-primary": checked,
},
)}
htmlFor={value}
>
<div className="flex items-center gap-2">
<RadioGroupItem
Expand All @@ -72,12 +73,12 @@ const RadioGroupItemBox = React.forwardRef<
checked={checked}
{...radioProps}
/>
<Label htmlFor={value}>{label}</Label>
<span>{label}</span>
</div>
{description && (
<p className="pl-6 text-sm text-muted-foreground">{description}</p>
)}
</div>
</label>
);
});

Expand Down
129 changes: 45 additions & 84 deletions client/src/containers/projects/form/assumptions/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import React from "react";

import { useFormContext } from "react-hook-form";

import { createColumnHelper } from "@tanstack/react-table";

import { formatNumber } from "@/lib/format";

import CellValue from "@/containers/projects/form/cell-value";
import { DataColumnDef } from "@/containers/projects/form/cost-inputs-overrides/constants";
import { CreateCustomProjectForm } from "@/containers/projects/form/setup";

import {
FormControl,
FormField,
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";

export type AssumptionsFormProperty =
Expand All @@ -24,77 +14,48 @@ export type AssumptionsFormProperty =
const columnHelper =
createColumnHelper<DataColumnDef<AssumptionsFormProperty>>();

export const COLUMNS = () => {
const form = useFormContext<CreateCustomProjectForm>();

return [
columnHelper.accessor("label", {
header: () => <span>Cost</span>,
cell: (props) => {
return (
<Label
tooltip={{
title: props.getValue(),
// todo: update with descriptions
content: props.getValue(),
}}
>
{props.getValue()}
</Label>
);
},
}),
columnHelper.accessor("defaultValue", {
header: () => <span>Base value</span>,
cell: (props) => {
const value = props.getValue();
if (value === null || value === undefined) {
return "-";
export const COLUMNS = [
columnHelper.accessor("label", {
header: () => <span>Cost</span>,
cell: (props) => {
return (
<Label
tooltip={{
title: props.getValue(),
// todo: update with descriptions
content: props.getValue(),
}}
>
{props.getValue()}
</Label>
);
},
}),
columnHelper.accessor("defaultValue", {
header: () => <span>Base value</span>,
cell: (props) => {
const value = props.getValue();
if (value === null || value === undefined) {
return "-";
}

if (!Number(value)) return value;

return formatNumber(Number(value));
},
}),
columnHelper.accessor("unit", {
header: () => <span>Unit</span>,
}),
columnHelper.accessor("value", {
header: () => <span>Override value</span>,
cell: (props) => (
<CellValue
name={
props.row.original
.property as keyof CreateCustomProjectForm["assumptions"]
}

if (!Number(value)) return value;

return formatNumber(Number(value));
},
}),
columnHelper.accessor("unit", {
header: () => <span>Unit</span>,
}),
columnHelper.accessor("value", {
header: () => <span>Override value</span>,
cell: (props) => {
return (
<FormField
control={form.control}
/*
// @ts-expect-error fix later */
name={props.row.original.property}
render={({ field }) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { value, ...restField } = field;

return (
<FormItem>
<FormControl>
<Input
type="number"
placeholder="Insert value"
min={0}
{...restField}
// defaultValue={props.row.original.value}
onChange={(e) => {
field.onChange(Number(e.target.value));
}}
value={field.value as number}
/>
</FormControl>
<FormMessage />
</FormItem>
);
}}
/>
);
},
}),
];
};
/>
),
}),
];
8 changes: 5 additions & 3 deletions client/src/containers/projects/form/assumptions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useMemo } from "react";

import { useFormContext } from "react-hook-form";

import { ASSUMPTIONS_NAME_TO_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
Expand Down Expand Up @@ -56,19 +58,19 @@ export default function AssumptionsProjectForm() {
label: name,
unit,
property:
`assumption.${ASSUMPTIONS_NAME_TO_DTO_MAP[name as keyof typeof ASSUMPTIONS_NAME_TO_DTO_MAP]}` as AssumptionsFormProperty,
`assumptions.${ASSUMPTIONS_NAME_TO_DTO_MAP[name as keyof typeof ASSUMPTIONS_NAME_TO_DTO_MAP]}` as AssumptionsFormProperty,
defaultValue: value,
value: Number(value),
})),
},
);

console.log({ data });
// const c = useMemo(() => COLUMNS(), []);

const table = useReactTable({
// @ts-expect-error fix later
data: isSuccess ? data : NO_DATA,
columns: COLUMNS(),
columns: COLUMNS,
getCoreRowModel: getCoreRowModel(),
});

Expand Down
45 changes: 45 additions & 0 deletions client/src/containers/projects/form/cell-value.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useFormContext } from "react-hook-form";

import { CreateCustomProjectForm } from "@/containers/projects/form/setup";

import {
FormControl,
FormField,
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";

export default function CellValue({
name,
}: {
name: keyof CreateCustomProjectForm;
}) {
const form = useFormContext<CreateCustomProjectForm>();

return (
<FormField
control={form.control}
name={name}
render={({ field }) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { value, ...restField } = field;

return (
<FormItem>
<FormControl>
<Input
{...restField}
type="number"
placeholder="Insert value"
min={0}
defaultValue={field.value as number}
/>
</FormControl>
<FormMessage />
</FormItem>
);
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,91 +1,67 @@
import React from "react";

import { useFormContext } from "react-hook-form";

import { createColumnHelper } from "@tanstack/react-table";

import { formatNumber } from "@/lib/format";

import CellValue from "@/containers/projects/form/cell-value";
import {
COST_INPUTS_KEYS,
DataColumnDef,
} from "@/containers/projects/form/cost-inputs-overrides/constants";
import { CreateCustomProjectForm } from "@/containers/projects/form/setup";

import {
FormControl,
FormField,
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";

export type CapexFormProperty =
`costInputs.${(typeof COST_INPUTS_KEYS)["capex"][number]}`;

const columnHelper = createColumnHelper<DataColumnDef<CapexFormProperty>>();

export const COLUMNS = () => {
const form = useFormContext<CreateCustomProjectForm>();

return [
columnHelper.accessor("label", {
header: () => <span>Capex</span>,
cell: (props) => {
return (
<Label
tooltip={{
title: props.getValue(),
// todo: update with descriptions
content: props.getValue(),
}}
>
{props.getValue()}
</Label>
);
},
}),
columnHelper.accessor("defaultValue", {
header: () => <span>Base value</span>,
cell: (props) => {
const value = props.getValue();
if (value === null || value === undefined) {
return "-";
}
export const COLUMNS = [
columnHelper.accessor("label", {
header: () => <span>Capex</span>,
cell: (props) => {
return (
<Label
tooltip={{
title: props.getValue(),
// todo: update with descriptions
content: props.getValue(),
}}
>
{props.getValue()}
</Label>
);
},
}),
columnHelper.accessor("defaultValue", {
header: () => <span>Base value</span>,
cell: (props) => {
const value = props.getValue();
if (value === null || value === undefined) {
return "-";
}

if (!Number(value)) return value;
if (!Number(value)) return value;

return formatNumber(Number(value));
},
}),
columnHelper.accessor("unit", {
header: () => <span>Unit</span>,
}),
columnHelper.accessor("value", {
header: () => <span>Override value</span>,
cell: (props) => {
return (
<FormField
control={form.control}
name={props.row.original.property}
render={({ field }) => (
<FormItem>
<FormControl>
<Input
type="number"
placeholder="Insert value"
min={0}
{...field}
value={field.value as number}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
);
},
}),
];
};
return formatNumber(Number(value));
},
}),
columnHelper.accessor("unit", {
header: () => <span>Unit</span>,
}),
columnHelper.accessor("value", {
header: () => <span>Override value</span>,
cell: (props) => {
return (
<CellValue
name={
props.row.original
.property as keyof CreateCustomProjectForm["costInputs"]
}
/>
);
},
}),
];
Loading

0 comments on commit fb93261

Please sign in to comment.