add code blank for last case/complaint

This commit is contained in:
smanylov
2026-04-16 17:34:14 +07:00
parent cbf30604af
commit fcc1f3bec9
3 changed files with 114 additions and 0 deletions
+70
View File
@@ -612,4 +612,74 @@ export async function createCase(
errorMessage: errors errorMessage: errors
} }
} }
}
export async function fetchLastCase() {
const token = await getSessionData('token');
try {
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
method: 'POST',
body: JSON.stringify({
version: 1,
msg_id: 30017,
message_body: {
action: "get_all",
token: token
}
}),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
if (response.ok) {
let parsed = await response.json();
if (parsed) {
return parsed;
} else {
throw null;
}
} else {
throw (`${response.status}`);
}
} catch (error) {
return null
}
}
export async function fetchLastComplaint() {
const token = await getSessionData('token');
try {
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
method: 'POST',
body: JSON.stringify({
version: 1,
msg_id: 30017,
message_body: {
action: "get_all",
token: token
}
}),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
if (response.ok) {
let parsed = await response.json();
if (parsed) {
return parsed;
} else {
throw null;
}
} else {
throw (`${response.status}`);
}
} catch (error) {
return null
}
} }
+22
View File
@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import { fetchLastCase } from '@/app/actions/violationActions';
export interface useLastCase {
test: number,
}
export const useLastCases = () => {
return useQuery({
queryKey: ['lastCases'],
queryFn: () => {
return fetchLastCase()
},
select: (data: useLastCase | null) => {
if (!data) {
return null
}
return data;
},
retry: false
});
};
@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import { fetchLastComplaint } from '@/app/actions/violationActions';
export interface useLastComplaint {
test: number,
}
export const useLastComplaints = () => {
return useQuery({
queryKey: ['lastComplaints'],
queryFn: () => {
return fetchLastComplaint()
},
select: (data: useLastComplaint | null) => {
if (!data) {
return null
}
return data;
},
retry: false
});
};