fix all eslint errors
This commit is contained in:
@@ -2,9 +2,9 @@ import { Button, Group, Modal, NumberInput, Select, TextInput, type ModalBasePro
|
||||
import { t } from "@/config/i18n";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { IconCancel, IconEdit, IconPlus } from "@tabler/icons-react";
|
||||
import { getProductors, getUsers } from "@/services/api";
|
||||
import { useGetProductors, useGetUsers } from "@/services/api";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useMemo } from "react";
|
||||
import type { Form, FormInputs } from "@/services/resources/forms";
|
||||
|
||||
export type FormModalProps = ModalBaseProps & {
|
||||
@@ -18,18 +18,18 @@ export default function FormModal({
|
||||
currentForm,
|
||||
handleSubmit
|
||||
}: FormModalProps) {
|
||||
const {data: productors} = getProductors();
|
||||
const {data: users} = getUsers();
|
||||
const {data: productors} = useGetProductors();
|
||||
const {data: users} = useGetUsers();
|
||||
|
||||
const form = useForm<FormInputs>({
|
||||
initialValues: {
|
||||
name: "",
|
||||
season: "",
|
||||
start: null,
|
||||
end: null,
|
||||
productor_id: "",
|
||||
referer_id: "",
|
||||
minimum_shipment_value: null,
|
||||
name: currentForm?.name ?? "",
|
||||
season: currentForm?.season ?? "",
|
||||
start: currentForm?.start ?? null,
|
||||
end: currentForm?.end ?? null,
|
||||
productor_id: currentForm?.productor?.id.toString() ?? "",
|
||||
referer_id: currentForm?.referer?.id.toString() ?? "",
|
||||
minimum_shipment_value: currentForm?.minimum_shipment_value ?? null,
|
||||
},
|
||||
validate: {
|
||||
name: (value) =>
|
||||
@@ -47,25 +47,13 @@ export default function FormModal({
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (currentForm) {
|
||||
form.setValues({
|
||||
...currentForm,
|
||||
start: currentForm.start || null,
|
||||
end: currentForm.end || null,
|
||||
productor_id: String(currentForm.productor.id),
|
||||
referer_id: String(currentForm.referer.id)
|
||||
});
|
||||
}
|
||||
}, [currentForm]);
|
||||
|
||||
const usersSelect = useMemo(() => {
|
||||
return users?.map(user => ({value: String(user.id), label: `${user.name}`}))
|
||||
}, [users])
|
||||
}, [users]);
|
||||
|
||||
const productorsSelect = useMemo(() => {
|
||||
return productors?.map(prod => ({value: String(prod.id), label: `${prod.name}`}))
|
||||
}, [productors])
|
||||
}, [productors]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ActionIcon, Table, Tooltip } from "@mantine/core";
|
||||
import { useNavigate, useSearchParams } from "react-router";
|
||||
import { deleteForm} from "@/services/api";
|
||||
import { useDeleteForm} from "@/services/api";
|
||||
import { IconEdit, IconX } from "@tabler/icons-react";
|
||||
import { t } from "@/config/i18n";
|
||||
import type { Form } from "@/services/resources/forms";
|
||||
@@ -12,8 +12,8 @@ export type FormRowProps = {
|
||||
export default function FormRow({
|
||||
form,
|
||||
}: FormRowProps) {
|
||||
const [searchParams, _] = useSearchParams();
|
||||
const deleteMutation = deleteForm();
|
||||
const [searchParams] = useSearchParams();
|
||||
const deleteMutation = useDeleteForm();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,6 @@ import { t } from "@/config/i18n";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { IconCancel } from "@tabler/icons-react";
|
||||
import { PaymentMethods, type Productor, type ProductorInputs } from "@/services/resources/productors";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export type ProductorModalProps = ModalBaseProps & {
|
||||
currentProductor?: Productor;
|
||||
@@ -18,10 +17,10 @@ export function ProductorModal({
|
||||
}: ProductorModalProps) {
|
||||
const form = useForm<ProductorInputs>({
|
||||
initialValues: {
|
||||
name: "",
|
||||
address: "",
|
||||
payment_methods: [],
|
||||
type: "",
|
||||
name: currentProductor?.name ?? "",
|
||||
address: currentProductor?.address ?? "",
|
||||
payment_methods: currentProductor?.payment_methods ?? [],
|
||||
type: currentProductor?.type ?? "",
|
||||
},
|
||||
validate: {
|
||||
name: (value) =>
|
||||
@@ -33,14 +32,6 @@ export function ProductorModal({
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (currentProductor) {
|
||||
form.setValues({
|
||||
...currentProductor,
|
||||
});
|
||||
}
|
||||
}, [currentProductor]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
@@ -128,7 +119,6 @@ export function ProductorModal({
|
||||
aria-label={currentProductor ? t("edit productor", {capfirst: true}) : t("create productor", {capfirst: true})}
|
||||
onClick={() => {
|
||||
form.validate();
|
||||
console.log(form.getValues())
|
||||
if (form.isValid()) {
|
||||
handleSubmit(form.getValues(), currentProductor?.id)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ActionIcon, Badge, Table, Tooltip } from "@mantine/core";
|
||||
import { t } from "@/config/i18n";
|
||||
import { IconEdit, IconX } from "@tabler/icons-react";
|
||||
import type { Productor } from "@/services/resources/productors";
|
||||
import { deleteProductor } from "@/services/api";
|
||||
import { useDeleteProductor } from "@/services/api";
|
||||
import { useNavigate, useSearchParams } from "react-router";
|
||||
|
||||
export type ProductorRowProps = {
|
||||
@@ -12,8 +12,8 @@ export type ProductorRowProps = {
|
||||
export default function ProductorRow({
|
||||
productor,
|
||||
}: ProductorRowProps) {
|
||||
const [searchParams, _] = useSearchParams();
|
||||
const deleteMutation = deleteProductor();
|
||||
const [searchParams] = useSearchParams();
|
||||
const deleteMutation = useDeleteProductor();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,9 +2,9 @@ import { Button, Group, Modal, NumberInput, Select, TextInput, Title, type Modal
|
||||
import { t } from "@/config/i18n";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { IconCancel } from "@tabler/icons-react";
|
||||
import { ProductQuantityUnit, productToProductInputs, ProductUnit, type Product, type ProductInputs } from "@/services/resources/products";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { getProductors } from "@/services/api";
|
||||
import { ProductQuantityUnit, ProductUnit, type Product, type ProductInputs } from "@/services/resources/products";
|
||||
import { useMemo } from "react";
|
||||
import { useGetProductors } from "@/services/api";
|
||||
import { InputLabel } from "@/components/Label";
|
||||
|
||||
export type ProductModalProps = ModalBaseProps & {
|
||||
@@ -18,17 +18,17 @@ export function ProductModal({
|
||||
currentProduct,
|
||||
handleSubmit
|
||||
}: ProductModalProps) {
|
||||
const {data: productors} = getProductors();
|
||||
const {data: productors} = useGetProductors();
|
||||
const form = useForm<ProductInputs>({
|
||||
initialValues: {
|
||||
name: "",
|
||||
unit: null,
|
||||
price: null,
|
||||
price_kg: null,
|
||||
quantity: null,
|
||||
quantity_unit: null,
|
||||
type: null,
|
||||
productor_id: null,
|
||||
name: currentProduct?.name ?? "",
|
||||
unit: currentProduct?.unit ?? null,
|
||||
price: currentProduct?.price ?? null,
|
||||
price_kg: currentProduct?.price_kg ?? null,
|
||||
quantity: currentProduct?.quantity ?? null,
|
||||
quantity_unit: currentProduct?.quantity_unit ?? null,
|
||||
type: currentProduct?.type ?? null,
|
||||
productor_id: currentProduct ? String(currentProduct.productor.id) : null,
|
||||
},
|
||||
validate: {
|
||||
name: (value) =>
|
||||
@@ -45,16 +45,10 @@ export function ProductModal({
|
||||
!value ? `${t("productor", {capfirst: true})} ${t('is required')}` : null
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (currentProduct) {
|
||||
form.setValues(productToProductInputs(currentProduct));
|
||||
}
|
||||
}, [currentProduct]);
|
||||
|
||||
const productorsSelect = useMemo(() => {
|
||||
return productors?.map(productor => ({value: String(productor.id), label: `${productor.name}`}))
|
||||
}, [productors])
|
||||
}, [productors]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ActionIcon, Table, Tooltip } from "@mantine/core";
|
||||
import { t } from "@/config/i18n";
|
||||
import { IconEdit, IconX } from "@tabler/icons-react";
|
||||
import { ProductType, ProductUnit, type Product } from "@/services/resources/products";
|
||||
import { deleteProduct } from "@/services/api";
|
||||
import { useDeleteProduct } from "@/services/api";
|
||||
import { useNavigate, useSearchParams } from "react-router";
|
||||
|
||||
export type ProductRowProps = {
|
||||
@@ -12,8 +12,8 @@ export type ProductRowProps = {
|
||||
export default function ProductRow({
|
||||
product,
|
||||
}: ProductRowProps) {
|
||||
const [searchParams, _] = useSearchParams();
|
||||
const deleteMutation = deleteProduct();
|
||||
const [searchParams] = useSearchParams();
|
||||
const deleteMutation = useDeleteProduct();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,8 +3,8 @@ import type { Shipment } from "@/services/resources/shipments";
|
||||
import { ProductForm } from "@/components/Products/Form";
|
||||
import type { UseFormReturnType } from "@mantine/form";
|
||||
import { useMemo } from "react";
|
||||
import { computePrices } from "@/pages/Contract";
|
||||
import { t } from "@/config/i18n";
|
||||
import { computePrices } from "@/pages/Contract/price";
|
||||
|
||||
export type ShipmentFormProps = {
|
||||
inputForm: UseFormReturnType<Record<string, string | number>>;
|
||||
@@ -27,7 +27,7 @@ export default function ShipmentForm({
|
||||
key.split("-")[1] === String(shipment.id)
|
||||
);
|
||||
return computePrices(values, shipment.products);
|
||||
}, [inputForm, shipment.products]);
|
||||
}, [inputForm, shipment.products, shipment.id]);
|
||||
|
||||
const priceRequirement = useMemo(() => {
|
||||
if (!minimumPrice)
|
||||
|
||||
@@ -3,9 +3,9 @@ import { t } from "@/config/i18n";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { IconCancel } from "@tabler/icons-react";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { shipmentToShipmentInputs, type Shipment, type ShipmentInputs } from "@/services/resources/shipments";
|
||||
import { getForms, getProductors, getProducts } from "@/services/api";
|
||||
import { useMemo } from "react";
|
||||
import { type Shipment, type ShipmentInputs } from "@/services/resources/shipments";
|
||||
import { useGetForms, useGetProductors, useGetProducts } from "@/services/api";
|
||||
|
||||
export type ShipmentModalProps = ModalBaseProps & {
|
||||
currentShipment?: Shipment;
|
||||
@@ -20,10 +20,10 @@ export default function ShipmentModal({
|
||||
}: ShipmentModalProps) {
|
||||
const form = useForm<ShipmentInputs>({
|
||||
initialValues: {
|
||||
name: "",
|
||||
date: null,
|
||||
form_id: "",
|
||||
product_ids: []
|
||||
name: currentShipment?.name ?? "",
|
||||
date: currentShipment?.date ?? null,
|
||||
form_id: currentShipment ? String(currentShipment?.form_id) : "",
|
||||
product_ids: currentShipment?.products.map((el) => (String(el.id))) ?? []
|
||||
},
|
||||
validate: {
|
||||
name: (value) =>
|
||||
@@ -35,18 +35,12 @@ export default function ShipmentModal({
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (currentShipment) {
|
||||
form.setValues(shipmentToShipmentInputs(currentShipment));
|
||||
}
|
||||
}, [currentShipment]);
|
||||
const { data: allForms } = useGetForms();
|
||||
const { data: allProducts } = useGetProducts(new URLSearchParams("types=1"));
|
||||
const { data: allProductors } = useGetProductors()
|
||||
|
||||
const { data: allForms } = getForms();
|
||||
const { data: allProducts } = getProducts(new URLSearchParams("types=1"));
|
||||
const { data: allProductors } = getProductors()
|
||||
|
||||
const formsSelect = useMemo(() => {
|
||||
return allForms?.map(form => ({value: String(form.id), label: `${form.name} ${form.season}`}))
|
||||
return allForms?.map(currentForm => ({value: String(currentForm.id), label: `${currentForm.name} ${currentForm.season}`}))
|
||||
}, [allForms]);
|
||||
|
||||
const productsSelect = useMemo(() => {
|
||||
@@ -60,7 +54,7 @@ export default function ShipmentModal({
|
||||
.map((product) => ({value: String(product.id), label: `${product.name}`}))
|
||||
}
|
||||
});
|
||||
}, [allProducts, form]);
|
||||
}, [allProductors, allProducts]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ActionIcon, Table, Tooltip } from "@mantine/core";
|
||||
import { useNavigate, useSearchParams } from "react-router";
|
||||
import { deleteShipment} from "@/services/api";
|
||||
import { useDeleteShipment} from "@/services/api";
|
||||
import { IconEdit, IconX } from "@tabler/icons-react";
|
||||
import { t } from "@/config/i18n";
|
||||
import type { Shipment } from "@/services/resources/shipments";
|
||||
@@ -12,8 +12,8 @@ export type ShipmentRowProps = {
|
||||
export default function ShipmentRow({
|
||||
shipment,
|
||||
}: ShipmentRowProps) {
|
||||
const [searchParams, _] = useSearchParams();
|
||||
const deleteMutation = deleteShipment();
|
||||
const [searchParams] = useSearchParams();
|
||||
const deleteMutation = useDeleteShipment();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,7 +3,6 @@ import { t } from "@/config/i18n";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { IconCancel } from "@tabler/icons-react";
|
||||
import { type User, type UserInputs } from "@/services/resources/users";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export type UserModalProps = ModalBaseProps & {
|
||||
currentUser?: User;
|
||||
@@ -18,8 +17,8 @@ export function UserModal({
|
||||
}: UserModalProps) {
|
||||
const form = useForm<UserInputs>({
|
||||
initialValues: {
|
||||
name: "",
|
||||
email: ""
|
||||
name: currentUser?.name ?? "",
|
||||
email: currentUser?.email ?? ""
|
||||
},
|
||||
validate: {
|
||||
name: (value) =>
|
||||
@@ -29,12 +28,6 @@ export function UserModal({
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (currentUser) {
|
||||
form.setValues(currentUser);
|
||||
}
|
||||
}, [currentUser]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
opened={opened}
|
||||
@@ -72,7 +65,6 @@ export function UserModal({
|
||||
aria-label={currentUser ? t("edit user", {capfirst: true}) : t('create user', {capfirst: true})}
|
||||
onClick={() => {
|
||||
form.validate();
|
||||
console.log(form.isValid(), form.getValues())
|
||||
if (form.isValid()) {
|
||||
handleSubmit(form.getValues(), currentUser?.id)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { ActionIcon, Table, Tooltip } from "@mantine/core";
|
||||
import { t } from "@/config/i18n";
|
||||
import { IconEdit, IconX } from "@tabler/icons-react";
|
||||
import { type User, type UserInputs } from "@/services/resources/users";
|
||||
import { UserModal } from "@/components/Users/Modal";
|
||||
import { deleteUser, getUser } from "@/services/api";
|
||||
import { type User } from "@/services/resources/users";
|
||||
import { useDeleteUser } from "@/services/api";
|
||||
import { useNavigate, useSearchParams } from "react-router";
|
||||
|
||||
export type UserRowProps = {
|
||||
@@ -13,8 +12,8 @@ export type UserRowProps = {
|
||||
export default function UserRow({
|
||||
user,
|
||||
}: UserRowProps) {
|
||||
const [searchParams, _] = useSearchParams();
|
||||
const deleteMutation = deleteUser();
|
||||
const [searchParams] = useSearchParams();
|
||||
const deleteMutation = useDeleteUser();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user