refactor(forklifts): more refactoring to improve during production
This commit is contained in:
@@ -28,6 +28,7 @@ router.post("/", async (req: Request, res: Response) => {
|
|||||||
companyId: req.body.companyId,
|
companyId: req.body.companyId,
|
||||||
invoiceNumber: req.body.invoiceNumber,
|
invoiceNumber: req.body.invoiceNumber,
|
||||||
invoiceDate: req.body.invoiceDate,
|
invoiceDate: req.body.invoiceDate,
|
||||||
|
comment: req.body.comment,
|
||||||
uploadedBy: req.body.uploadedBy,
|
uploadedBy: req.body.uploadedBy,
|
||||||
totalAmount: req.body.totalAmount,
|
totalAmount: req.body.totalAmount,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { numeric, pgTable, serial, uuid } from "drizzle-orm/pg-core";
|
import { numeric, pgTable, serial, text, uuid } from "drizzle-orm/pg-core";
|
||||||
import { createInsertSchema } from "drizzle-zod";
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { forklifts } from "./forklifts.js";
|
import { forklifts } from "./forklifts.js";
|
||||||
import { leaseInvoices } from "./leaseInvoices.js";
|
import { leaseInvoices } from "./leaseInvoices.js";
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export const leaseInvoices = pgTable("lease_invoices", {
|
|||||||
invoiceNumber: text("invoice_number").unique().notNull(),
|
invoiceNumber: text("invoice_number").unique().notNull(),
|
||||||
invoiceDate: date("invoice_date").notNull(),
|
invoiceDate: date("invoice_date").notNull(),
|
||||||
totalAmount: numeric("total_amount"),
|
totalAmount: numeric("total_amount"),
|
||||||
|
comment: text("comment"),
|
||||||
add_date: timestamp("add_date"),
|
add_date: timestamp("add_date"),
|
||||||
uploadedBy: text("uploaded_by"),
|
uploadedBy: text("uploaded_by"),
|
||||||
});
|
});
|
||||||
|
|||||||
28
frontend/src/lib/formStuff/components/TextArea.tsx
Normal file
28
frontend/src/lib/formStuff/components/TextArea.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { Label } from "../../../components/ui/label";
|
||||||
|
import { useFieldContext } from "..";
|
||||||
|
import { FieldErrors } from "./FieldErrors";
|
||||||
|
|
||||||
|
type InputFieldProps = {
|
||||||
|
label: string;
|
||||||
|
placeHolder: string;
|
||||||
|
required: boolean;
|
||||||
|
};
|
||||||
|
export const TextArea = ({ label, placeHolder, required }: InputFieldProps) => {
|
||||||
|
const field = useFieldContext<any>();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid gap-3 w-64">
|
||||||
|
<Label htmlFor={field.name}>{label}</Label>
|
||||||
|
<Textarea
|
||||||
|
id={field.name}
|
||||||
|
value={field.state.value}
|
||||||
|
onChange={(e) => field.handleChange(e.target.value)}
|
||||||
|
placeholder={placeHolder}
|
||||||
|
onBlur={field.handleBlur}
|
||||||
|
required={required}
|
||||||
|
/>
|
||||||
|
<FieldErrors meta={field.state.meta} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -5,6 +5,7 @@ import { InputField } from "./components/InputField";
|
|||||||
import { InputPasswordField } from "./components/InputPasswordField";
|
import { InputPasswordField } from "./components/InputPasswordField";
|
||||||
import { SelectField } from "./components/SelectField";
|
import { SelectField } from "./components/SelectField";
|
||||||
import { SubmitButton } from "./components/SubmitButton";
|
import { SubmitButton } from "./components/SubmitButton";
|
||||||
|
import { TextArea } from "./components/TextArea";
|
||||||
|
|
||||||
export const { fieldContext, useFieldContext, formContext, useFormContext } =
|
export const { fieldContext, useFieldContext, formContext, useFormContext } =
|
||||||
createFormHookContexts();
|
createFormHookContexts();
|
||||||
@@ -16,6 +17,7 @@ export const { useAppForm } = createFormHook({
|
|||||||
SelectField,
|
SelectField,
|
||||||
CheckboxField,
|
CheckboxField,
|
||||||
DateField,
|
DateField,
|
||||||
|
TextArea,
|
||||||
},
|
},
|
||||||
formComponents: { SubmitButton },
|
formComponents: { SubmitButton },
|
||||||
fieldContext,
|
fieldContext,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { getServers } from "@/lib/querys/admin/getServers";
|
import { getServers } from "@/lib/querys/admin/getServers";
|
||||||
|
import { getForklifts } from "@/lib/querys/forklifts/getForklifts";
|
||||||
import { getLeases } from "@/lib/querys/forklifts/getLeases";
|
import { getLeases } from "@/lib/querys/forklifts/getLeases";
|
||||||
import { useAppForm } from "../../../../lib/formStuff";
|
import { useAppForm } from "../../../../lib/formStuff";
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ const pfc: any = [
|
|||||||
export default function NewForklift({ setOpenDialog }: { setOpenDialog: any }) {
|
export default function NewForklift({ setOpenDialog }: { setOpenDialog: any }) {
|
||||||
//const search = useSearch({ from: "/_app/(auth)/login" });
|
//const search = useSearch({ from: "/_app/(auth)/login" });
|
||||||
const { data: s, isLoading: es } = useQuery(getServers());
|
const { data: s, isLoading: es } = useQuery(getServers());
|
||||||
|
const { refetch: refetchLifts } = useQuery(getForklifts());
|
||||||
const {
|
const {
|
||||||
data: leases,
|
data: leases,
|
||||||
isLoading: leaseError,
|
isLoading: leaseError,
|
||||||
@@ -91,6 +93,7 @@ export default function NewForklift({ setOpenDialog }: { setOpenDialog: any }) {
|
|||||||
form.reset();
|
form.reset();
|
||||||
setOpenDialog(false);
|
setOpenDialog(false);
|
||||||
refetch();
|
refetch();
|
||||||
|
refetchLifts();
|
||||||
toast.success(`${value.serialNumber} was just created `);
|
toast.success(`${value.serialNumber} was just created `);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export default function NewInvoice({
|
|||||||
invoiceNumber: "",
|
invoiceNumber: "",
|
||||||
invoiceDate: "",
|
invoiceDate: "",
|
||||||
totalAmount: "",
|
totalAmount: "",
|
||||||
|
comment: "",
|
||||||
forklifts: [{ forklift_id: "", serialNumber: "", amount: "" }],
|
forklifts: [{ forklift_id: "", serialNumber: "", amount: "" }],
|
||||||
},
|
},
|
||||||
onSubmit: async ({ value }) => {
|
onSubmit: async ({ value }) => {
|
||||||
@@ -198,6 +199,16 @@ export default function NewInvoice({
|
|||||||
<field.DateField label="Invoice Date" required={true} />
|
<field.DateField label="Invoice Date" required={true} />
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<form.AppField
|
||||||
|
name="comment"
|
||||||
|
children={(field) => (
|
||||||
|
<field.TextArea
|
||||||
|
label="Comment"
|
||||||
|
placeHolder="Enter your comment if needed."
|
||||||
|
required={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<hr className="mt-2 mb-2" />
|
<hr className="mt-2 mb-2" />
|
||||||
{/* Dynamic forklift section */}
|
{/* Dynamic forklift section */}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type Invoices = {
|
|||||||
id: string;
|
id: string;
|
||||||
invoiceNumber: string;
|
invoiceNumber: string;
|
||||||
invoiceDate: Date;
|
invoiceDate: Date;
|
||||||
|
comment: string;
|
||||||
totalAmount: string;
|
totalAmount: string;
|
||||||
add_date: Date;
|
add_date: Date;
|
||||||
};
|
};
|
||||||
@@ -83,6 +84,26 @@ function RouteComponent() {
|
|||||||
return <span>{format(date, "MM/dd/yyyy")}</span>;
|
return <span>{format(date, "MM/dd/yyyy")}</span>;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
columnHelper.accessor("comment", {
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
<span className="flex flex-row gap-2">Invoice Date</span>
|
||||||
|
{column.getIsSorted() === "asc" ? (
|
||||||
|
<ArrowUp className="ml-2 h-4 w-4" />
|
||||||
|
) : (
|
||||||
|
<ArrowDown className="ml-2 h-4 w-4" />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ getValue }) => {
|
||||||
|
return <span>{getValue()}</span>;
|
||||||
|
},
|
||||||
|
}),
|
||||||
// columnHelper.accessor("add_date", {
|
// columnHelper.accessor("add_date", {
|
||||||
// header: ({ column }) => {
|
// header: ({ column }) => {
|
||||||
// return (
|
// return (
|
||||||
|
|||||||
Reference in New Issue
Block a user