Skip to content

Commit

Permalink
feat: updated default values custom project form + refactor form tables
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas committed Jan 30, 2025
1 parent 3d4fc9d commit e286d9e
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 248 deletions.
67 changes: 3 additions & 64 deletions client/src/containers/projects/form/assumptions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { useFormContext } from "react-hook-form";

import { ASSUMPTIONS_NAME_TO_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
import {
flexRender,
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";

import { client } from "@/lib/query-client";
import { queryKeys } from "@/lib/query-keys";
Expand All @@ -16,21 +12,14 @@ import {
} from "@/containers/projects/form/assumptions/columns";
import { DataColumnDef } from "@/containers/projects/form/cost-inputs-overrides/constants";
import { CustomProjectForm } from "@/containers/projects/form/setup";
import FormTable from "@/containers/projects/form/table";

import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";

export const NO_DATA: DataColumnDef<AssumptionsFormProperty>[] = [];

Expand Down Expand Up @@ -88,57 +77,7 @@ export default function AssumptionsProjectForm() {
</div>
</AccordionTrigger>
<AccordionContent className="pb-0">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id} className="divide-x-0">
{headerGroup.headers.map((header) => {
return (
<TableHead
key={header.id}
className="bg-transparent font-normal"
>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
);
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
className="divide-x-0 divide-y-0 border-b-0"
>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="py-3">
{flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell
colSpan={COLUMNS.length}
className="h-24 text-center"
>
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
<FormTable table={table} totalColumnsLength={COLUMNS.length} />
</AccordionContent>
</AccordionItem>
</Accordion>
Expand Down
13 changes: 13 additions & 0 deletions client/src/containers/projects/form/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ACTIVITY } from "@shared/entities/activity.enum";

export const DEFAULT_FORM_VALUES = {
activity: ACTIVITY.CONSERVATION,
projectSizeHa: 10000, // activity === ACTIVITY.CONSERVATION ? 10000 : 100
projectSpecificLossRate: -0.003,
projectSpecificEmissionFactor: 15,
emissionFactorAGB: 200,
emissionFactorSOC: 15,
plantingSuccessRate: 0.8,
projectSpecificSequestrationRate: 15,
initialCarbonPriceAssumption: 30,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { useFormContext } from "react-hook-form";

import { ACTIVITY } from "@shared/entities/activity.enum";
import { COSTS_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
import {
flexRender,
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";

import { client } from "@/lib/query-client";
import { queryKeys } from "@/lib/query-keys";
Expand All @@ -20,15 +16,7 @@ import {
DataColumnDef,
} from "@/containers/projects/form/cost-inputs-overrides/constants";
import { CustomProjectForm } from "@/containers/projects/form/setup";

import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import FormTable from "@/containers/projects/form/table";

const NO_DATA: DataColumnDef<CapexFormProperty>[] = [];

Expand Down Expand Up @@ -94,48 +82,5 @@ export default function CapexCostInputsTable() {
getCoreRowModel: getCoreRowModel(),
});

return (
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id} className="divide-x-0">
{headerGroup.headers.map((header) => {
return (
<TableHead
key={header.id}
className="bg-transparent font-normal"
>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
);
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow key={row.id} className="divide-x-0 divide-y-0 border-b-0">
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="py-3">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={COLUMNS.length} className="h-24 text-center">
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
);
return <FormTable table={table} totalColumnsLength={COLUMNS.length} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { useFormContext } from "react-hook-form";

import { ACTIVITY } from "@shared/entities/activity.enum";
import { COSTS_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
import {
flexRender,
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";

import { client } from "@/lib/query-client";
import { queryKeys } from "@/lib/query-keys";
Expand All @@ -20,15 +16,7 @@ import {
OpexFormProperty,
} from "@/containers/projects/form/cost-inputs-overrides/opex/columns";
import { CustomProjectForm } from "@/containers/projects/form/setup";

import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import FormTable from "@/containers/projects/form/table";

const NO_DATA: DataColumnDef<OpexFormProperty>[] = [];

Expand Down Expand Up @@ -91,48 +79,5 @@ export default function OpexCostInputsTable() {
getCoreRowModel: getCoreRowModel(),
});

return (
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id} className="divide-x-0">
{headerGroup.headers.map((header) => {
return (
<TableHead
key={header.id}
className="bg-transparent font-normal"
>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
);
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow key={row.id} className="divide-x-0 divide-y-0 border-b-0">
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="py-3">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={COLUMNS.length} className="h-24 text-center">
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
);
return <FormTable table={table} totalColumnsLength={COLUMNS.length} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { useFormContext } from "react-hook-form";

import { ACTIVITY } from "@shared/entities/activity.enum";
import { COSTS_DTO_MAP } from "@shared/schemas/assumptions/assumptions.enums";
import {
flexRender,
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";

import { client } from "@/lib/query-client";
import { queryKeys } from "@/lib/query-keys";
Expand All @@ -20,15 +16,7 @@ import {
OtherFormProperty,
} from "@/containers/projects/form/cost-inputs-overrides/other/columns";
import { CustomProjectForm } from "@/containers/projects/form/setup";

import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import FormTable from "@/containers/projects/form/table";

const NO_DATA: DataColumnDef<OtherFormProperty>[] = [];

Expand Down Expand Up @@ -91,48 +79,5 @@ export default function OtherCostInputsTable() {
getCoreRowModel: getCoreRowModel(),
});

return (
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id} className="divide-x-0">
{headerGroup.headers.map((header) => {
return (
<TableHead
key={header.id}
className="bg-transparent font-normal"
>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
);
})}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow key={row.id} className="divide-x-0 divide-y-0 border-b-0">
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id} className="py-3">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={COLUMNS.length} className="h-24 text-center">
No results.
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
);
return <FormTable table={table} totalColumnsLength={COLUMNS.length} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { toDecimalPercentageValue, toPercentageValue } from "@/lib/format";
import { client } from "@/lib/query-client";
import { queryKeys } from "@/lib/query-keys";

import { DEFAULT_FORM_VALUES } from "@/containers/projects/form/constants";
import { CustomProjectForm } from "@/containers/projects/form/setup";

import { Card } from "@/components/ui/card";
Expand Down Expand Up @@ -281,6 +282,9 @@ export default function RestorationProjectDetails() {
<div className="relative flex flex-1 items-center">
<Input
{...field}
defaultValue={
DEFAULT_FORM_VALUES.projectSpecificSequestrationRate
}
className="w-full pr-12"
type="number"
onChange={(v) => {
Expand Down
Loading

0 comments on commit e286d9e

Please sign in to comment.