[WIP] front api exchanges
This commit is contained in:
72
frontend/src/components/CreateProduct/index.tsx
Normal file
72
frontend/src/components/CreateProduct/index.tsx
Normal file
@@ -0,0 +1,72 @@
|
||||
import { Grid, NumberInput, Paper, Select, Stack, TextInput } from "@mantine/core";
|
||||
import { t } from "../../config/i18n";
|
||||
|
||||
export type CreateProductProps = {
|
||||
form: Record<string, any>;
|
||||
}
|
||||
|
||||
export default function CreateProduct({form}: CreateProductProps) {
|
||||
return (
|
||||
<Stack>
|
||||
<Grid>
|
||||
<Grid.Col span={{ base: 12, md: 6, lg: 6 }}>
|
||||
<TextInput
|
||||
label={t("product name")}
|
||||
placeholder={t("product name")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('name')}
|
||||
/>
|
||||
<NumberInput
|
||||
label={t("product price")}
|
||||
placeholder={t("product price")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('price')}
|
||||
/>
|
||||
<TextInput
|
||||
label={t("product weight")}
|
||||
placeholder={t("product weight")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('weight')}
|
||||
/>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={{ base: 12, md: 6, lg: 6 }}>
|
||||
<Select
|
||||
label={t("product type")}
|
||||
placeholder={t("product type")}
|
||||
radius="sm"
|
||||
data={[
|
||||
{value: "1", label: t("planned")},
|
||||
{value: "2", label: t("reccurent")}
|
||||
]}
|
||||
defaultValue={"1"}
|
||||
clearable
|
||||
{...form.getInputProps('type')}
|
||||
/>
|
||||
<NumberInput
|
||||
label={t("product price kg")}
|
||||
placeholder={t("product price kg")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('pricekg')}
|
||||
/>
|
||||
<Select
|
||||
label={t("product unit")}
|
||||
placeholder={t("product unit")}
|
||||
radius="sm"
|
||||
data={[
|
||||
{value: "1", label: t("grams")},
|
||||
{value: "2", label: t("kilo")},
|
||||
{value: "3", label: t("piece")}
|
||||
]}
|
||||
defaultValue={"2"}
|
||||
clearable
|
||||
{...form.getInputProps('unit')}
|
||||
/>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
62
frontend/src/components/CreateProductorModal/index.tsx
Normal file
62
frontend/src/components/CreateProductorModal/index.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Button, Group, Loader, Modal, Text, TextInput, Title, type ModalBaseProps } from "@mantine/core";
|
||||
import { t } from "../../config/i18n";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { IconCancel, IconPlus } from "@tabler/icons-react";
|
||||
import { createProductor, type Productor } from "../../services/api";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function CreateProductorModal({opened, onClose}: ModalBaseProps) {
|
||||
const form = useForm<Productor>();
|
||||
const mutation = createProductor();
|
||||
|
||||
return (
|
||||
<Modal
|
||||
size="50%"
|
||||
opened={opened}
|
||||
onClose={onClose}
|
||||
title={t("create productor")}
|
||||
>
|
||||
<Title order={4}>{t("Informations")}</Title>
|
||||
<TextInput
|
||||
label={t("productor name")}
|
||||
placeholder={t("productor name")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('name')}
|
||||
/>
|
||||
<TextInput
|
||||
label={t("productor address")}
|
||||
placeholder={t("productor address")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('address')}
|
||||
/>
|
||||
<TextInput
|
||||
label={t("productor payment")}
|
||||
placeholder={t("productor payment")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('payment')}
|
||||
/>
|
||||
{mutation.isError ? <Text>{t("an error occured")}:{mutation.error.message}</Text> : null}
|
||||
{mutation.isSuccess ? <Text>{t("success")}</Text> : null}
|
||||
<Group mt="sm" justify="space-between">
|
||||
<Button
|
||||
variant="filled"
|
||||
color="red"
|
||||
aria-label={t("cancel")}
|
||||
leftSection={<IconCancel/>}
|
||||
onClick={onClose}
|
||||
>{t("cancel")}</Button>
|
||||
<Button
|
||||
variant="filled"
|
||||
aria-label={t("create productor")}
|
||||
leftSection={mutation.isPending ? <Loader/> : <IconPlus/>}
|
||||
onClick={() => {
|
||||
mutation.mutate(form.getValues());
|
||||
}}
|
||||
>{t("create productor")}</Button>
|
||||
</Group>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
56
frontend/src/components/CreateShipmentModal/index.tsx
Normal file
56
frontend/src/components/CreateShipmentModal/index.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Button, Group, Loader, Modal, Text, TextInput, Title, type ModalBaseProps } from "@mantine/core";
|
||||
import { t } from "../../config/i18n";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { IconCancel, IconPlus } from "@tabler/icons-react";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { createShipment, type ShipmentCreate } from "../../services/api";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function CreateShipmentModal({opened, onClose}: ModalBaseProps) {
|
||||
const form = useForm<ShipmentCreate>();
|
||||
const mutation = createShipment();
|
||||
|
||||
return (
|
||||
<Modal
|
||||
size="50%"
|
||||
opened={opened}
|
||||
onClose={onClose}
|
||||
title={t("create shipment")}
|
||||
>
|
||||
<Title order={4}>{t("informations")}</Title>
|
||||
<TextInput
|
||||
label={t("shipment name")}
|
||||
placeholder={t("shipment name")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('name')}
|
||||
/>
|
||||
<DatePickerInput
|
||||
label={t("shipment date")}
|
||||
placeholder={t("shipment date")}
|
||||
radius="sm"
|
||||
withAsterisk
|
||||
{...form.getInputProps('date')}
|
||||
/>
|
||||
{mutation.isError ? <Text>{t("an error occured")}:{mutation.error.message}</Text> : null}
|
||||
{mutation.isSuccess ? <Text>{t("success")}</Text> : null}
|
||||
<Group mt="sm" justify="space-between">
|
||||
<Button
|
||||
variant="filled"
|
||||
color="red"
|
||||
aria-label={t("cancel")}
|
||||
leftSection={<IconCancel/>}
|
||||
onClick={onClose}
|
||||
>{t("cancel")}</Button>
|
||||
<Button
|
||||
variant="filled"
|
||||
aria-label={t("create shipment")}
|
||||
leftSection={mutation.isPending ? <Loader/> : <IconPlus/>}
|
||||
onClick={() => {
|
||||
mutation.mutate({...form.getValues(), product_ids: []});
|
||||
}}
|
||||
>{t("create shipment")}</Button>
|
||||
</Group>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user