@@ -38,6 +38,7 @@ export type Opportunity = {
|
||||
expected_impact: string | null;
|
||||
financing_modality: string | null;
|
||||
status: string;
|
||||
last_validated_at?: string | null;
|
||||
};
|
||||
export type Context = {
|
||||
primary_territory_path?: { id: string; name: string; location_type: string }[];
|
||||
@@ -118,15 +119,16 @@ export async function api(url: string, body?: unknown) {
|
||||
.find((c) => c.startsWith("XSRF-TOKEN="))
|
||||
?.slice(11) ?? "",
|
||||
);
|
||||
const formData = typeof FormData !== "undefined" && body instanceof FormData;
|
||||
const response = await fetch(url, {
|
||||
method: body === undefined ? "GET" : "POST",
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
...(formData ? {} : { "Content-Type": "application/json" }),
|
||||
"X-XSRF-TOKEN": token,
|
||||
},
|
||||
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
||||
...(body === undefined ? {} : { body: formData ? body : JSON.stringify(body) }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.message ?? "Não foi possível concluir a operação.");
|
||||
|
||||
Reference in New Issue
Block a user