add prettier code formater
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
import { useMutation, useQuery, useQueryClient,type DefinedInitialDataOptions,type UseQueryResult } from "@tanstack/react-query";
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
type DefinedInitialDataOptions,
|
||||
type UseQueryResult,
|
||||
} from "@tanstack/react-query";
|
||||
import { Config } from "@/config/config";
|
||||
import type { Form, FormCreate, FormEditPayload } from "@/services/resources/forms";
|
||||
import type { Shipment, ShipmentCreate, ShipmentEditPayload } from "@/services/resources/shipments";
|
||||
import type { Productor, ProductorCreate, ProductorEditPayload } from "@/services/resources/productors";
|
||||
import type {
|
||||
Productor,
|
||||
ProductorCreate,
|
||||
ProductorEditPayload,
|
||||
} from "@/services/resources/productors";
|
||||
import type { User, UserCreate, UserEditPayload } from "@/services/resources/users";
|
||||
import type { Product, ProductCreate, ProductEditPayload } from "./resources/products";
|
||||
import type { ContractCreate } from "./resources/contracts";
|
||||
@@ -10,559 +20,558 @@ import { notifications } from "@mantine/notifications";
|
||||
import { t } from "@/config/i18n";
|
||||
|
||||
export function useGetShipments(filters?: URLSearchParams): UseQueryResult<Shipment[], Error> {
|
||||
const queryString = filters?.toString()
|
||||
const queryString = filters?.toString();
|
||||
return useQuery<Shipment[]>({
|
||||
queryKey: ['shipments', queryString],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/shipments${filters ? `?${queryString}` : ""}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
queryKey: ["shipments", queryString],
|
||||
queryFn: () =>
|
||||
fetch(`${Config.backend_uri}/shipments${filters ? `?${queryString}` : ""}`).then(
|
||||
(res) => res.json(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetShipment(id?: number, options?: Partial<DefinedInitialDataOptions<Shipment, Error, Shipment, readonly unknown[]>>): UseQueryResult<Shipment, Error> {
|
||||
export function useGetShipment(
|
||||
id?: number,
|
||||
options?: Partial<DefinedInitialDataOptions<Shipment, Error, Shipment, readonly unknown[]>>,
|
||||
): UseQueryResult<Shipment, Error> {
|
||||
return useQuery<Shipment>({
|
||||
queryKey: ['shipment'],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/shipments/${id}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
enabled: !!id,
|
||||
queryKey: ["shipment"],
|
||||
queryFn: () => fetch(`${Config.backend_uri}/shipments/${id}`).then((res) => res.json()),
|
||||
enabled: !!id,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateShipment() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (newShipment: ShipmentCreate) => {
|
||||
return fetch(`${Config.backend_uri}/shipments`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newShipment),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created shipment", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully created shipment", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['shipments'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["shipments"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing shipment`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing shipment`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEditShipment() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({shipment, id}: ShipmentEditPayload) => {
|
||||
mutationFn: ({ shipment, id }: ShipmentEditPayload) => {
|
||||
return fetch(`${Config.backend_uri}/shipments/${id}`, {
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(shipment),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited shipment", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully edited shipment", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['shipments'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["shipments"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing shipment`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing shipment`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteShipment() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => {
|
||||
return fetch(`${Config.backend_uri}/shipments/${id}`, {
|
||||
method: 'DELETE',
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully deleted shipment", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully deleted shipment", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['shipments'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["shipments"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error deleting shipment`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error deleting shipment`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetProductors(filters?: URLSearchParams): UseQueryResult<Productor[], Error> {
|
||||
const queryString = filters?.toString()
|
||||
const queryString = filters?.toString();
|
||||
return useQuery<Productor[]>({
|
||||
queryKey: ['productors', queryString],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/productors${filters ? `?${queryString}` : ""}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
queryKey: ["productors", queryString],
|
||||
queryFn: () =>
|
||||
fetch(`${Config.backend_uri}/productors${filters ? `?${queryString}` : ""}`).then(
|
||||
(res) => res.json(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetProductor(id?: number, options?: Partial<DefinedInitialDataOptions<Productor, Error, Productor, readonly unknown[]>>) {
|
||||
export function useGetProductor(
|
||||
id?: number,
|
||||
options?: Partial<DefinedInitialDataOptions<Productor, Error, Productor, readonly unknown[]>>,
|
||||
) {
|
||||
return useQuery<Productor>({
|
||||
queryKey: ['productor'],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/productors/${id}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
enabled: !!id,
|
||||
queryKey: ["productor"],
|
||||
queryFn: () => fetch(`${Config.backend_uri}/productors/${id}`).then((res) => res.json()),
|
||||
enabled: !!id,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateProductor() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (newProductor: ProductorCreate) => {
|
||||
return fetch(`${Config.backend_uri}/productors`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newProductor),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created productor", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully created productor", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['productors'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["productors"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing productor`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing productor`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEditProductor() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({productor, id}: ProductorEditPayload) => {
|
||||
mutationFn: ({ productor, id }: ProductorEditPayload) => {
|
||||
return fetch(`${Config.backend_uri}/productors/${id}`, {
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(productor),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited productor", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully edited productor", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['productors'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["productors"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing productor`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing productor`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteProductor() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => {
|
||||
return fetch(`${Config.backend_uri}/productors/${id}`, {
|
||||
method: 'DELETE',
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully deleted productor", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully deleted productor", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['productors'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["productors"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error deleting productor`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error deleting productor`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetForm(id?: number, options?: Partial<DefinedInitialDataOptions<Form, Error, Form, readonly unknown[]>>) {
|
||||
export function useGetForm(
|
||||
id?: number,
|
||||
options?: Partial<DefinedInitialDataOptions<Form, Error, Form, readonly unknown[]>>,
|
||||
) {
|
||||
return useQuery<Form>({
|
||||
queryKey: ['form'],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/forms/${id}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
enabled: !!id,
|
||||
queryKey: ["form"],
|
||||
queryFn: () => fetch(`${Config.backend_uri}/forms/${id}`).then((res) => res.json()),
|
||||
enabled: !!id,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetForms(filters?: URLSearchParams): UseQueryResult<Form[], Error> {
|
||||
const queryString = filters?.toString()
|
||||
export function useGetForms(filters?: URLSearchParams): UseQueryResult<Form[], Error> {
|
||||
const queryString = filters?.toString();
|
||||
return useQuery<Form[]>({
|
||||
queryKey: ['forms', queryString],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/forms${filters ? `?${queryString}` : ""}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
queryKey: ["forms", queryString],
|
||||
queryFn: () =>
|
||||
fetch(`${Config.backend_uri}/forms${filters ? `?${queryString}` : ""}`).then((res) =>
|
||||
res.json(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateForm() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (newForm: FormCreate) => {
|
||||
return fetch(`${Config.backend_uri}/forms`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newForm),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ['forms'] })
|
||||
}
|
||||
await queryClient.invalidateQueries({ queryKey: ["forms"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteForm() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => {
|
||||
return fetch(`${Config.backend_uri}/forms/${id}`, {
|
||||
method: 'DELETE',
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully deleted form", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully deleted form", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['forms'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["forms"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error deleting form`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error deleting form`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEditForm() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({id, form}: FormEditPayload) => {
|
||||
mutationFn: ({ id, form }: FormEditPayload) => {
|
||||
return fetch(`${Config.backend_uri}/forms/${id}`, {
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(form),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited form", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully edited form", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['forms'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["forms"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing form`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing form`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetProduct(id?: number, options?: Partial<DefinedInitialDataOptions<Product, Error, Product, readonly unknown[]>>) {
|
||||
export function useGetProduct(
|
||||
id?: number,
|
||||
options?: Partial<DefinedInitialDataOptions<Product, Error, Product, readonly unknown[]>>,
|
||||
) {
|
||||
return useQuery<Product>({
|
||||
queryKey: ['product'],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/products/${id}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
enabled: !!id,
|
||||
queryKey: ["product"],
|
||||
queryFn: () => fetch(`${Config.backend_uri}/products/${id}`).then((res) => res.json()),
|
||||
enabled: !!id,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetProducts(filters?: URLSearchParams): UseQueryResult<Product[], Error> {
|
||||
const queryString = filters?.toString()
|
||||
export function useGetProducts(filters?: URLSearchParams): UseQueryResult<Product[], Error> {
|
||||
const queryString = filters?.toString();
|
||||
return useQuery<Product[]>({
|
||||
queryKey: ['products', queryString],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/products${filters ? `?${queryString}` : ""}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
queryKey: ["products", queryString],
|
||||
queryFn: () =>
|
||||
fetch(`${Config.backend_uri}/products${filters ? `?${queryString}` : ""}`).then((res) =>
|
||||
res.json(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateProduct() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (newProduct: ProductCreate) => {
|
||||
return fetch(`${Config.backend_uri}/products`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newProduct),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created product", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully created product", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['products'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["products"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing product`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing product`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteProduct() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => {
|
||||
return fetch(`${Config.backend_uri}/products/${id}`, {
|
||||
method: 'DELETE',
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully deleted product", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully deleted product", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['products'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["products"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error deleting product`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error deleting product`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEditProduct() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({id, product}: ProductEditPayload) => {
|
||||
mutationFn: ({ id, product }: ProductEditPayload) => {
|
||||
return fetch(`${Config.backend_uri}/products/${id}`, {
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(product),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited product", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully edited product", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['products'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["products"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing product`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing product`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetUser(id?: number, options?: Partial<DefinedInitialDataOptions<User, Error, User, readonly unknown[]>>) {
|
||||
export function useGetUser(
|
||||
id?: number,
|
||||
options?: Partial<DefinedInitialDataOptions<User, Error, User, readonly unknown[]>>,
|
||||
) {
|
||||
return useQuery<User>({
|
||||
queryKey: ['user'],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/users/${id}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
enabled: !!id,
|
||||
queryKey: ["user"],
|
||||
queryFn: () => fetch(`${Config.backend_uri}/users/${id}`).then((res) => res.json()),
|
||||
enabled: !!id,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetUsers(filters?: URLSearchParams): UseQueryResult<User[], Error> {
|
||||
const queryString = filters?.toString()
|
||||
export function useGetUsers(filters?: URLSearchParams): UseQueryResult<User[], Error> {
|
||||
const queryString = filters?.toString();
|
||||
return useQuery<User[]>({
|
||||
queryKey: ['users', queryString],
|
||||
queryFn: () => (
|
||||
fetch(`${Config.backend_uri}/users${filters ? `?${queryString}` : ""}`)
|
||||
.then((res) => res.json())
|
||||
),
|
||||
queryKey: ["users", queryString],
|
||||
queryFn: () =>
|
||||
fetch(`${Config.backend_uri}/users${filters ? `?${queryString}` : ""}`).then((res) =>
|
||||
res.json(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateUser() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (newUser: UserCreate) => {
|
||||
return fetch(`${Config.backend_uri}/users`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newUser),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created user", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully created user", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['users'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["users"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing user`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing user`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteUser() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => {
|
||||
return fetch(`${Config.backend_uri}/users/${id}`, {
|
||||
method: 'DELETE',
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully deleted user", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully deleted user", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['users'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["users"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error deleting user`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error deleting user`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEditUser() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({id, user}: UserEditPayload) => {
|
||||
mutationFn: ({ id, user }: UserEditPayload) => {
|
||||
return fetch(`${Config.backend_uri}/users/${id}`, {
|
||||
method: 'PUT',
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(user),
|
||||
}).then((res) => res.json());
|
||||
},
|
||||
onSuccess: async () => {
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited user", {capfirst: true}),
|
||||
title: t("success", { capfirst: true }),
|
||||
message: t("successfully edited user", { capfirst: true }),
|
||||
});
|
||||
await queryClient.invalidateQueries({ queryKey: ['users'] })
|
||||
await queryClient.invalidateQueries({ queryKey: ["users"] });
|
||||
},
|
||||
onError: (error) => {
|
||||
notifications.show({
|
||||
title: t("error", {capfirst: true}),
|
||||
message: error?.message || t(`error editing user`, {capfirst: true}),
|
||||
color: "red"
|
||||
title: t("error", { capfirst: true }),
|
||||
message: error?.message || t(`error editing user`, { capfirst: true }),
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function useCreateContract() {
|
||||
const queryClient = useQueryClient()
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (newContract: ContractCreate) => {
|
||||
return fetch(`${Config.backend_uri}/contracts`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(newContract),
|
||||
}).then(async (res) => await res.blob());
|
||||
@@ -575,6 +584,6 @@ export function useCreateContract() {
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
await queryClient.invalidateQueries({ queryKey: ["contracts"] });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type ContractCreate = {
|
||||
form_id: number;
|
||||
contract: Record<string, string | number | null>;
|
||||
}
|
||||
export type ContractCreate = {
|
||||
form_id: number;
|
||||
contract: Record<string, string | number | null>;
|
||||
};
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
import type { Productor } from "@/services/resources/productors";
|
||||
import type { Shipment } from "@/services/resources/shipments";
|
||||
import type { User } from "@/services/resources/users";
|
||||
|
||||
export type Form = {
|
||||
id: number;
|
||||
name: string;
|
||||
season: string;
|
||||
start: string;
|
||||
end: string;
|
||||
productor: Productor;
|
||||
referer: User;
|
||||
shipments: Shipment[];
|
||||
minimum_shipment_value: number | null;
|
||||
}
|
||||
|
||||
export type FormCreate = {
|
||||
name: string;
|
||||
season: string;
|
||||
start: string;
|
||||
end: string;
|
||||
productor_id: number;
|
||||
referer_id: number;
|
||||
minimum_shipment_value: number | null;
|
||||
}
|
||||
|
||||
export type FormEdit = {
|
||||
name?: string | null;
|
||||
season?: string | null;
|
||||
start?: string | null;
|
||||
end?: string | null;
|
||||
productor_id?: number | null;
|
||||
referer_id?: number | null;
|
||||
minimum_shipment_value: number | null;
|
||||
}
|
||||
|
||||
export type FormEditPayload = {
|
||||
id: number;
|
||||
form: FormEdit;
|
||||
}
|
||||
|
||||
export type FormInputs = {
|
||||
name: string;
|
||||
season: string;
|
||||
start: string | null;
|
||||
end: string | null;
|
||||
productor_id: string;
|
||||
referer_id: string;
|
||||
minimum_shipment_value: number | string | null;
|
||||
}
|
||||
import type { Productor } from "@/services/resources/productors";
|
||||
import type { Shipment } from "@/services/resources/shipments";
|
||||
import type { User } from "@/services/resources/users";
|
||||
|
||||
export type Form = {
|
||||
id: number;
|
||||
name: string;
|
||||
season: string;
|
||||
start: string;
|
||||
end: string;
|
||||
productor: Productor;
|
||||
referer: User;
|
||||
shipments: Shipment[];
|
||||
minimum_shipment_value: number | null;
|
||||
};
|
||||
|
||||
export type FormCreate = {
|
||||
name: string;
|
||||
season: string;
|
||||
start: string;
|
||||
end: string;
|
||||
productor_id: number;
|
||||
referer_id: number;
|
||||
minimum_shipment_value: number | null;
|
||||
};
|
||||
|
||||
export type FormEdit = {
|
||||
name?: string | null;
|
||||
season?: string | null;
|
||||
start?: string | null;
|
||||
end?: string | null;
|
||||
productor_id?: number | null;
|
||||
referer_id?: number | null;
|
||||
minimum_shipment_value: number | null;
|
||||
};
|
||||
|
||||
export type FormEditPayload = {
|
||||
id: number;
|
||||
form: FormEdit;
|
||||
};
|
||||
|
||||
export type FormInputs = {
|
||||
name: string;
|
||||
season: string;
|
||||
start: string | null;
|
||||
end: string | null;
|
||||
productor_id: string;
|
||||
referer_id: string;
|
||||
minimum_shipment_value: number | string | null;
|
||||
};
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
import { t } from "@/config/i18n";
|
||||
import type { Product } from "./products";
|
||||
|
||||
export const PaymentMethods = [
|
||||
{value: "cheque", label: t("cheque", {capfirst: true})},
|
||||
{value: "transfer", label: t("transfer", {capfirst: true})},
|
||||
]
|
||||
|
||||
export type PaymentMethod = {
|
||||
name: string;
|
||||
details: string;
|
||||
}
|
||||
|
||||
export type Productor = {
|
||||
id: number;
|
||||
name: string;
|
||||
address: string;
|
||||
payment_methods: PaymentMethod[];
|
||||
type: string;
|
||||
products: Product[]
|
||||
}
|
||||
|
||||
export type ProductorCreate = {
|
||||
name: string;
|
||||
address: string;
|
||||
payment_methods: PaymentMethod[];
|
||||
type: string;
|
||||
}
|
||||
|
||||
export type ProductorEdit = {
|
||||
name: string | null;
|
||||
address: string | null;
|
||||
payment_methods: PaymentMethod[];
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
export type ProductorInputs = {
|
||||
name: string;
|
||||
address: string;
|
||||
type: string;
|
||||
payment_methods: PaymentMethod[];
|
||||
}
|
||||
|
||||
export type ProductorEditPayload = {
|
||||
productor: ProductorEdit;
|
||||
id: number;
|
||||
}
|
||||
import { t } from "@/config/i18n";
|
||||
import type { Product } from "./products";
|
||||
|
||||
export const PaymentMethods = [
|
||||
{ value: "cheque", label: t("cheque", { capfirst: true }) },
|
||||
{ value: "transfer", label: t("transfer", { capfirst: true }) },
|
||||
];
|
||||
|
||||
export type PaymentMethod = {
|
||||
name: string;
|
||||
details: string;
|
||||
};
|
||||
|
||||
export type Productor = {
|
||||
id: number;
|
||||
name: string;
|
||||
address: string;
|
||||
payment_methods: PaymentMethod[];
|
||||
type: string;
|
||||
products: Product[];
|
||||
};
|
||||
|
||||
export type ProductorCreate = {
|
||||
name: string;
|
||||
address: string;
|
||||
payment_methods: PaymentMethod[];
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type ProductorEdit = {
|
||||
name: string | null;
|
||||
address: string | null;
|
||||
payment_methods: PaymentMethod[];
|
||||
type: string | null;
|
||||
};
|
||||
|
||||
export type ProductorInputs = {
|
||||
name: string;
|
||||
address: string;
|
||||
type: string;
|
||||
payment_methods: PaymentMethod[];
|
||||
};
|
||||
|
||||
export type ProductorEditPayload = {
|
||||
productor: ProductorEdit;
|
||||
id: number;
|
||||
};
|
||||
|
||||
@@ -1,100 +1,106 @@
|
||||
import type { Productor } from "@/services/resources/productors";
|
||||
import type { Shipment } from "@/services/resources/shipments";
|
||||
|
||||
type ProductTypeKey = "1" | "2";
|
||||
type ProductUnitKey = "1" | "2" | "3";
|
||||
|
||||
export const ProductType = {
|
||||
"1": "planned",
|
||||
"2": "recurrent",
|
||||
};
|
||||
|
||||
export const ProductUnit = {
|
||||
"1": "grams",
|
||||
"2": "kilo",
|
||||
"3": "piece",
|
||||
};
|
||||
|
||||
export const ProductQuantityUnit = {
|
||||
"ml": "mililiter",
|
||||
"L": "liter",
|
||||
"g": "grams",
|
||||
"kg": "kilo"
|
||||
}
|
||||
|
||||
export type Product = {
|
||||
id: number;
|
||||
productor: Productor;
|
||||
name: string;
|
||||
unit: ProductUnitKey;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
quantity: number | null;
|
||||
quantity_unit: string | null;
|
||||
type: ProductTypeKey;
|
||||
shipments: Shipment[];
|
||||
}
|
||||
|
||||
export type ProductCreate = {
|
||||
productor_id: number;
|
||||
name: string;
|
||||
unit: string;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
quantity: number | null;
|
||||
quantity_unit: string | null;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export type ProductEdit = {
|
||||
productor_id: number | null;
|
||||
name: string | null;
|
||||
unit: string | null;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
quantity: number | null;
|
||||
quantity_unit: string | null;
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
export type ProductInputs = {
|
||||
productor_id: string | null;
|
||||
name: string;
|
||||
unit: string | null;
|
||||
price: number | string | null;
|
||||
price_kg: number | string | null;
|
||||
quantity: number | string | null;
|
||||
quantity_unit: string | null;
|
||||
type: string | null;
|
||||
}
|
||||
|
||||
export type ProductEditPayload = {
|
||||
product: ProductEdit;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export function productToProductInputs(product: Product): ProductInputs {
|
||||
return {
|
||||
productor_id: String(product.productor.id),
|
||||
name: product.name,
|
||||
unit: product.unit,
|
||||
price: product.price,
|
||||
price_kg: product.price_kg,
|
||||
quantity: product.quantity,
|
||||
quantity_unit: product.quantity_unit,
|
||||
type: product.type,
|
||||
};
|
||||
}
|
||||
|
||||
export function productCreateFromProductInputs(productInput: ProductInputs): ProductCreate {
|
||||
return {
|
||||
productor_id: Number(productInput.productor_id)!,
|
||||
name: productInput.name,
|
||||
unit: productInput.unit!,
|
||||
price: productInput.price === "" || !productInput.price ? null : Number(productInput.price),
|
||||
price_kg: productInput.price_kg === "" || !productInput.price_kg ? null : Number(productInput.price_kg),
|
||||
quantity: productInput.quantity === "" || !productInput.quantity ? null : Number(productInput.quantity),
|
||||
quantity_unit: productInput.quantity_unit,
|
||||
type: productInput.type!,
|
||||
}
|
||||
}
|
||||
import type { Productor } from "@/services/resources/productors";
|
||||
import type { Shipment } from "@/services/resources/shipments";
|
||||
|
||||
type ProductTypeKey = "1" | "2";
|
||||
type ProductUnitKey = "1" | "2" | "3";
|
||||
|
||||
export const ProductType = {
|
||||
"1": "planned",
|
||||
"2": "recurrent",
|
||||
};
|
||||
|
||||
export const ProductUnit = {
|
||||
"1": "grams",
|
||||
"2": "kilo",
|
||||
"3": "piece",
|
||||
};
|
||||
|
||||
export const ProductQuantityUnit = {
|
||||
ml: "mililiter",
|
||||
L: "liter",
|
||||
g: "grams",
|
||||
kg: "kilo",
|
||||
};
|
||||
|
||||
export type Product = {
|
||||
id: number;
|
||||
productor: Productor;
|
||||
name: string;
|
||||
unit: ProductUnitKey;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
quantity: number | null;
|
||||
quantity_unit: string | null;
|
||||
type: ProductTypeKey;
|
||||
shipments: Shipment[];
|
||||
};
|
||||
|
||||
export type ProductCreate = {
|
||||
productor_id: number;
|
||||
name: string;
|
||||
unit: string;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
quantity: number | null;
|
||||
quantity_unit: string | null;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type ProductEdit = {
|
||||
productor_id: number | null;
|
||||
name: string | null;
|
||||
unit: string | null;
|
||||
price: number | null;
|
||||
price_kg: number | null;
|
||||
quantity: number | null;
|
||||
quantity_unit: string | null;
|
||||
type: string | null;
|
||||
};
|
||||
|
||||
export type ProductInputs = {
|
||||
productor_id: string | null;
|
||||
name: string;
|
||||
unit: string | null;
|
||||
price: number | string | null;
|
||||
price_kg: number | string | null;
|
||||
quantity: number | string | null;
|
||||
quantity_unit: string | null;
|
||||
type: string | null;
|
||||
};
|
||||
|
||||
export type ProductEditPayload = {
|
||||
product: ProductEdit;
|
||||
id: number;
|
||||
};
|
||||
|
||||
export function productToProductInputs(product: Product): ProductInputs {
|
||||
return {
|
||||
productor_id: String(product.productor.id),
|
||||
name: product.name,
|
||||
unit: product.unit,
|
||||
price: product.price,
|
||||
price_kg: product.price_kg,
|
||||
quantity: product.quantity,
|
||||
quantity_unit: product.quantity_unit,
|
||||
type: product.type,
|
||||
};
|
||||
}
|
||||
|
||||
export function productCreateFromProductInputs(productInput: ProductInputs): ProductCreate {
|
||||
return {
|
||||
productor_id: Number(productInput.productor_id)!,
|
||||
name: productInput.name,
|
||||
unit: productInput.unit!,
|
||||
price: productInput.price === "" || !productInput.price ? null : Number(productInput.price),
|
||||
price_kg:
|
||||
productInput.price_kg === "" || !productInput.price_kg
|
||||
? null
|
||||
: Number(productInput.price_kg),
|
||||
quantity:
|
||||
productInput.quantity === "" || !productInput.quantity
|
||||
? null
|
||||
: Number(productInput.quantity),
|
||||
quantity_unit: productInput.quantity_unit,
|
||||
type: productInput.type!,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
import type { Form } from "./forms";
|
||||
import type { Product } from "./products";
|
||||
|
||||
export type Shipment = {
|
||||
name: string;
|
||||
date: string;
|
||||
id: number;
|
||||
form: Form;
|
||||
form_id: number;
|
||||
products: Product[];
|
||||
}
|
||||
|
||||
export type ShipmentCreate = {
|
||||
name: string;
|
||||
date: string;
|
||||
form_id: number;
|
||||
product_ids: number[];
|
||||
}
|
||||
|
||||
export type ShipmentEdit = {
|
||||
name: string | null;
|
||||
date: string | null;
|
||||
form_id: number | null;
|
||||
product_ids: number[];
|
||||
}
|
||||
|
||||
export type ShipmentEditPayload = {
|
||||
id: number;
|
||||
shipment: ShipmentEdit;
|
||||
}
|
||||
|
||||
export type ShipmentInputs = {
|
||||
name: string | null;
|
||||
date: string | null;
|
||||
form_id: string | null;
|
||||
product_ids: string[];
|
||||
}
|
||||
|
||||
export function shipmentToShipmentInputs(shipment: Shipment): ShipmentInputs {
|
||||
return {
|
||||
...shipment,
|
||||
form_id: String(shipment.form_id),
|
||||
product_ids: shipment.products.map((el) => (String(el.id)))
|
||||
};
|
||||
}
|
||||
|
||||
export function shipmentCreateFromShipmentInputs(shipmentInput: ShipmentInputs): ShipmentCreate {
|
||||
return {
|
||||
name: shipmentInput.name!,
|
||||
date: shipmentInput.date!,
|
||||
form_id: Number(shipmentInput.form_id),
|
||||
product_ids: shipmentInput.product_ids.map(el => (Number(el))),
|
||||
}
|
||||
}
|
||||
import type { Form } from "./forms";
|
||||
import type { Product } from "./products";
|
||||
|
||||
export type Shipment = {
|
||||
name: string;
|
||||
date: string;
|
||||
id: number;
|
||||
form: Form;
|
||||
form_id: number;
|
||||
products: Product[];
|
||||
};
|
||||
|
||||
export type ShipmentCreate = {
|
||||
name: string;
|
||||
date: string;
|
||||
form_id: number;
|
||||
product_ids: number[];
|
||||
};
|
||||
|
||||
export type ShipmentEdit = {
|
||||
name: string | null;
|
||||
date: string | null;
|
||||
form_id: number | null;
|
||||
product_ids: number[];
|
||||
};
|
||||
|
||||
export type ShipmentEditPayload = {
|
||||
id: number;
|
||||
shipment: ShipmentEdit;
|
||||
};
|
||||
|
||||
export type ShipmentInputs = {
|
||||
name: string | null;
|
||||
date: string | null;
|
||||
form_id: string | null;
|
||||
product_ids: string[];
|
||||
};
|
||||
|
||||
export function shipmentToShipmentInputs(shipment: Shipment): ShipmentInputs {
|
||||
return {
|
||||
...shipment,
|
||||
form_id: String(shipment.form_id),
|
||||
product_ids: shipment.products.map((el) => String(el.id)),
|
||||
};
|
||||
}
|
||||
|
||||
export function shipmentCreateFromShipmentInputs(shipmentInput: ShipmentInputs): ShipmentCreate {
|
||||
return {
|
||||
name: shipmentInput.name!,
|
||||
date: shipmentInput.date!,
|
||||
form_id: Number(shipmentInput.form_id),
|
||||
product_ids: shipmentInput.product_ids.map((el) => Number(el)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import type { Product } from "@/services/resources/products";
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
products: Product[];
|
||||
}
|
||||
|
||||
export type UserInputs = {
|
||||
email: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UserCreate ={
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
}
|
||||
|
||||
export type UserEdit ={
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
}
|
||||
|
||||
export type UserEditPayload = {
|
||||
user: UserEdit;
|
||||
id: number;
|
||||
}
|
||||
import type { Product } from "@/services/resources/products";
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
products: Product[];
|
||||
};
|
||||
|
||||
export type UserInputs = {
|
||||
email: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type UserCreate = {
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
};
|
||||
|
||||
export type UserEdit = {
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
};
|
||||
|
||||
export type UserEditPayload = {
|
||||
user: UserEdit;
|
||||
id: number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user