-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
416 additions
and
352 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
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,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> | ||
); | ||
}} | ||
/> | ||
); | ||
} |
116 changes: 46 additions & 70 deletions
116
client/src/containers/projects/form/cost-inputs-overrides/capex/columns.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 |
---|---|---|
@@ -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"] | ||
} | ||
/> | ||
); | ||
}, | ||
}), | ||
]; |
Oops, something went wrong.