add shipment forms and start contract from form

This commit is contained in:
2026-02-13 01:12:42 +01:00
parent fe27595931
commit ef7403f213
20 changed files with 553 additions and 312 deletions

View File

@@ -6,16 +6,29 @@ import type { Productor, ProductorCreate, ProductorEditPayload } from "@/service
import type { User, UserCreate, UserEditPayload } from "@/services/resources/users";
import type { Product, ProductCreate, ProductEditPayload } from "./resources/products";
export function getShipments() {
export function getShipments(filters?: URLSearchParams): UseQueryResult<Shipment[], Error> {
const queryString = filters?.toString()
return useQuery<Shipment[]>({
queryKey: ['shipments'],
queryKey: ['shipments', queryString],
queryFn: () => (
fetch(`${Config.backend_uri}/shipments`)
fetch(`${Config.backend_uri}/shipments${filters ? `?${queryString}` : ""}`)
.then((res) => res.json())
),
});
}
export function getShipment(id?: number, options?: any): UseQueryResult<Shipment, Error> {
return useQuery<Shipment>({
queryKey: ['shipment'],
queryFn: () => (
fetch(`${Config.backend_uri}/shipments/${id}`)
.then((res) => res.json())
),
enabled: !!id,
...options,
});
}
export function createShipment() {
const queryClient = useQueryClient()
@@ -26,8 +39,7 @@ export function createShipment() {
headers: {
"Content-Type": "application/json"
},
// TODO change product ids hardcode here
body: JSON.stringify({...newShipment, product_ids: []}),
body: JSON.stringify(newShipment),
}).then((res) => res.json());
},
onSuccess: async () => {
@@ -40,13 +52,13 @@ export function editShipment() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: ({id, shipment}: ShipmentEditPayload) => {
mutationFn: ({shipment, id}: ShipmentEditPayload) => {
return fetch(`${Config.backend_uri}/shipments/${id}`, {
method: 'PUT',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({...shipment}),
body: JSON.stringify(shipment),
}).then((res) => res.json());
},
onSuccess: async () => {
@@ -55,6 +67,23 @@ export function editShipment() {
})
}
export function deleteShipment() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (id: number) => {
return fetch(`${Config.backend_uri}/shipments/${id}`, {
method: 'DELETE',
headers: {
"Content-Type": "application/json"
},
}).then((res) => res.json());
},
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ['shipments'] })
}
});
}
export function getProductors(filters?: URLSearchParams): UseQueryResult<Productor[], Error> {
const queryString = filters?.toString()
return useQuery<Productor[]>({