Add min cheque value and view contract at the end of form flow
This commit is contained in:
@@ -26,10 +26,17 @@ import { notifications } from "@mantine/notifications";
|
||||
import { t } from "@/config/i18n";
|
||||
|
||||
export async function refreshToken() {
|
||||
return await fetch(`${Config.backend_uri}/auth/refresh`, {method: "POST", credentials: "include"});
|
||||
return await fetch(`${Config.backend_uri}/auth/refresh`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchWithAuth(input: RequestInfo, options?: RequestInit, redirect: boolean = true) {
|
||||
export async function fetchWithAuth(
|
||||
input: RequestInfo,
|
||||
options?: RequestInit,
|
||||
redirect: boolean = true,
|
||||
) {
|
||||
const res = await fetch(input, {
|
||||
credentials: "include",
|
||||
...options,
|
||||
@@ -38,11 +45,10 @@ export async function fetchWithAuth(input: RequestInfo, options?: RequestInit, r
|
||||
if (res.status === 401) {
|
||||
const refresh = await refreshToken();
|
||||
if (refresh.status == 400 || refresh.status == 401) {
|
||||
if (redirect)
|
||||
window.location.href = `/?sessionExpired=True`;
|
||||
|
||||
if (redirect) window.location.href = `/?sessionExpired=True`;
|
||||
|
||||
const error = new Error("Unauthorized");
|
||||
error.cause = 401
|
||||
error.cause = 401;
|
||||
throw error;
|
||||
}
|
||||
const newRes = await fetch(input, {
|
||||
@@ -188,9 +194,7 @@ export function useGetProductors(filters?: URLSearchParams): UseQueryResult<Prod
|
||||
queryFn: () =>
|
||||
fetchWithAuth(`${Config.backend_uri}/productors${filters ? `?${queryString}` : ""}`, {
|
||||
credentials: "include",
|
||||
})
|
||||
.then((res) => res.json()
|
||||
),
|
||||
}).then((res) => res.json()),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -326,7 +330,9 @@ export function useGetForms(filters?: URLSearchParams): UseQueryResult<Form[], E
|
||||
return useQuery<Form[]>({
|
||||
queryKey: ["forms", queryString],
|
||||
queryFn: () =>
|
||||
fetch(`${Config.backend_uri}/forms${filters ? `?${queryString}` : ""}`).then((res) => res.json()),
|
||||
fetch(`${Config.backend_uri}/forms${filters ? `?${queryString}` : ""}`).then((res) =>
|
||||
res.json(),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -335,7 +341,9 @@ export function useGetReferentForms(filters?: URLSearchParams): UseQueryResult<F
|
||||
return useQuery<Form[]>({
|
||||
queryKey: ["forms", queryString],
|
||||
queryFn: () =>
|
||||
fetchWithAuth(`${Config.backend_uri}/forms/referents${filters ? `?${queryString}` : ""}`).then((res) => res.json()),
|
||||
fetchWithAuth(
|
||||
`${Config.backend_uri}/forms/referents${filters ? `?${queryString}` : ""}`,
|
||||
).then((res) => res.json()),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -723,8 +731,9 @@ export function useGetContractFile() {
|
||||
export function useGetContractFileTemplate() {
|
||||
return useMutation({
|
||||
mutationFn: async (form_id: number) => {
|
||||
const res = await fetchWithAuth(`${Config.backend_uri}/contracts/${form_id}/base`)
|
||||
.then((res) => res);
|
||||
const res = await fetchWithAuth(`${Config.backend_uri}/contracts/${form_id}/base`).then(
|
||||
(res) => res,
|
||||
);
|
||||
|
||||
if (!res.ok) throw new Error();
|
||||
const blob = await res.blob();
|
||||
@@ -746,7 +755,6 @@ export function useGetContractFileTemplate() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function useGetRecap() {
|
||||
return useMutation({
|
||||
mutationFn: async (form_id: number) => {
|
||||
@@ -822,13 +830,7 @@ export function useCreateContract() {
|
||||
: `contract_${newContract.form_id}.pdf`;
|
||||
return { blob, filename };
|
||||
},
|
||||
onSuccess: async ({ blob, filename }) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["contracts"] });
|
||||
},
|
||||
});
|
||||
@@ -880,10 +882,14 @@ export function useCurrentUser() {
|
||||
return useQuery<UserLogged>({
|
||||
queryKey: ["currentUser"],
|
||||
queryFn: () => {
|
||||
return fetchWithAuth(`${Config.backend_uri}/auth/user/me`, {
|
||||
credentials: "include",
|
||||
}, false).then((res) => res.json());
|
||||
return fetchWithAuth(
|
||||
`${Config.backend_uri}/auth/user/me`,
|
||||
{
|
||||
credentials: "include",
|
||||
},
|
||||
false,
|
||||
).then((res) => res.json());
|
||||
},
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export type PaymentMethod = {
|
||||
name: string;
|
||||
details: string;
|
||||
max: number | string | null;
|
||||
min: number | string | null;
|
||||
};
|
||||
|
||||
export type Productor = {
|
||||
|
||||
Reference in New Issue
Block a user