diff --git a/backend/src/models.py b/backend/src/models.py index 8d8e7ce..d7e7155 100644 --- a/backend/src/models.py +++ b/backend/src/models.py @@ -100,13 +100,13 @@ class FormPublic(FormBase): id: int productor: ProductorPublic | None referer: User | None - shipments: list["Shipment"] = [] + shipments: list["ShipmentPublic"] = [] class Form(FormBase, table=True): id: int | None = Field(default=None, primary_key=True) productor: Optional['Productor'] = Relationship() referer: Optional['User'] = Relationship() - shipments: list["Shipment"] = Relationship(cascade_delete=True) + shipments: list["Shipment"] = Relationship(back_populates="form", cascade_delete=True) class FormUpdate(SQLModel): name: str | None @@ -157,15 +157,18 @@ class ShipmentBase(SQLModel): class ShipmentPublic(ShipmentBase): id: int products: list[Product] = [] + form: Form | None class Shipment(ShipmentBase, table=True): id: int | None = Field(default=None, primary_key=True) products: list[Product] = Relationship(back_populates="shipments", link_model=ShipmentProductLink) + form: Optional[Form] = Relationship(back_populates="shipments") class ShipmentUpdate(SQLModel): name: str | None date: str | None - product_ids: list[int] = [] + product_ids: list[int] | None = [] class ShipmentCreate(ShipmentBase): - product_ids: list[int] | None \ No newline at end of file + product_ids: list[int] = [] + form_id: int \ No newline at end of file diff --git a/frontend/src/components/CreateProduct/index.tsx b/frontend/src/components/CreateProduct/index.tsx deleted file mode 100644 index 30a2b31..0000000 --- a/frontend/src/components/CreateProduct/index.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { Grid, NumberInput, Select, Stack, TextInput } from "@mantine/core"; -import { t } from "../../config/i18n"; - -export type CreateProductProps = { - form: Record; -} - -export default function CreateProduct({form}: CreateProductProps) { - return ( - - - - - - - - - - - - - ); -} \ No newline at end of file diff --git a/frontend/src/components/Forms/Card/index.tsx b/frontend/src/components/Forms/Card/index.tsx new file mode 100644 index 0000000..2644658 --- /dev/null +++ b/frontend/src/components/Forms/Card/index.tsx @@ -0,0 +1,38 @@ +import { Badge, Box, Group, Paper, Text, Title } from "@mantine/core"; +import { Link } from "react-router"; +import type { Form } from "@/services/resources/forms"; + +export type FormCardProps = { + form: Form; +} + +export function FormCard({form}: FormCardProps) { + return ( + + + + + {form.name} + + {form.season} + + + {form.productor.name} + {form.referer.name} + + + + + ); +} \ No newline at end of file diff --git a/frontend/src/components/Forms/Modal/index.tsx b/frontend/src/components/Forms/Modal/index.tsx index 5fea59c..76f228a 100644 --- a/frontend/src/components/Forms/Modal/index.tsx +++ b/frontend/src/components/Forms/Modal/index.tsx @@ -1,14 +1,11 @@ -import { ActionIcon, Button, Collapse, Group, Modal, NumberInput, Select, TextInput, type ModalBaseProps } from "@mantine/core"; +import { Button, Group, Modal, Select, TextInput, type ModalBaseProps } from "@mantine/core"; import { t } from "@/config/i18n"; import { DatePickerInput } from "@mantine/dates"; -import { IconCancel, IconChevronDown, IconChevronUp } from "@tabler/icons-react"; +import { IconCancel } from "@tabler/icons-react"; import { getProductors, getUsers } from "@/services/api"; import { useForm } from "@mantine/form"; -import { useCallback, useEffect, useMemo } from "react"; -import { useDisclosure } from "@mantine/hooks"; +import { useEffect, useMemo } from "react"; import type { Form, FormInputs } from "@/services/resources/forms"; -import type { ShipmentInputs } from "@/services/resources/shipments"; -import ShipmentForm from "@/components/Shipments/Form"; export type FormModalProps = ModalBaseProps & { currentForm?: Form; @@ -31,7 +28,6 @@ export default function FormModal({ end: null, productor_id: "", referer_id: "", - shipments: [], }, validate: { name: (value) => @@ -55,7 +51,6 @@ export default function FormModal({ ...currentForm, start: currentForm.start || null, end: currentForm.end || null, - shipments: currentForm.shipments || [], productor_id: String(currentForm.productor.id), referer_id: String(currentForm.referer.id) }); @@ -70,27 +65,6 @@ export default function FormModal({ return productors?.map(prod => ({value: String(prod.id), label: `${prod.name}`})) }, [productors]) - const [openedShipents, { toggle: toggleShipments }] = useDisclosure(true); - - const editShipmentElement = useCallback(( - index: number, - shipment: ShipmentInputs - ) => { - form.setFieldValue('shipments', (prev) => { - return prev.map((elem, id) => { - if (id === index) - return {...shipment} - return elem; - }) - }); - }, [form]) - - const deleteShipmentElement = useCallback((index: number) => { - form.setFieldValue('shipments', (prev) => { - return prev.filter((_, i) => i === index) - }); - }, [form]) - return ( - - { - const target = Number(value); - form.setFieldValue('shipments', (prev) => { - const itemsToAdd = Array.from( - {length: target - prev.length}, - () => ({name: "", date: "", form_id: null, id: null}) - ); - return ( - target > prev.length ? - [...prev, ...itemsToAdd] : - prev.slice(0, target) - ); - }) - }} - /> - - {openedShipents ? : } - - - - { - form.getValues().shipments.map((value, index) => - - ) - } -