QC Admin - User Menu Ekonomi : Jumlah Pengangguran
This commit is contained in:
@@ -1,37 +1,87 @@
|
||||
import ApiFetch from "@/lib/api-fetch";
|
||||
import { proxy } from "valtio";
|
||||
|
||||
interface FileStorageItem {
|
||||
id: string;
|
||||
name: string;
|
||||
path: string;
|
||||
link: string;
|
||||
realName: string;
|
||||
mimeType: string;
|
||||
category: string;
|
||||
isActive: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
deletedAt: Date | null;
|
||||
}
|
||||
|
||||
interface ApiResponse {
|
||||
data: FileStorageItem[];
|
||||
meta: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface ListItem {
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
total: number;
|
||||
realName: string;
|
||||
}
|
||||
|
||||
const stateListImage = proxy<{
|
||||
list: { name: string; url: string; total: number }[] | null;
|
||||
list: ListItem[] | null;
|
||||
page: number;
|
||||
count: number;
|
||||
total: number | undefined;
|
||||
load: (params?: { search?: string }) => Promise<void>;
|
||||
del: ({ name }: { name: string }) => Promise<void>;
|
||||
load: (params?: { search?: string; page?: number }) => Promise<void>;
|
||||
del: (params: { id: string }) => Promise<void>;
|
||||
}>({
|
||||
list: null,
|
||||
page: 1,
|
||||
count: 20,
|
||||
count: 10,
|
||||
total: undefined,
|
||||
async load(params?: { search?: string }) {
|
||||
const { search = "" } = params ?? {};
|
||||
const { data } = await ApiFetch.api.imgs.get({
|
||||
query: {
|
||||
page: this.page,
|
||||
count: this.count,
|
||||
search,
|
||||
},
|
||||
});
|
||||
this.list = data;
|
||||
if (data?.[0]?.total) {
|
||||
this.total = Math.ceil(data[0].total / this.count);
|
||||
} else {
|
||||
this.total = undefined;
|
||||
|
||||
async load(params?: { search?: string; page?: number }) {
|
||||
const { search = "", page = this.page } = params ?? {};
|
||||
this.page = page;
|
||||
|
||||
try {
|
||||
const response = await ApiFetch.api.fileStorage["findMany"].get({
|
||||
query: {
|
||||
page: this.page,
|
||||
search,
|
||||
},
|
||||
}) as { data: ApiResponse };
|
||||
|
||||
if (response?.data?.data) {
|
||||
this.list = response.data.data.map((file) => ({
|
||||
id: file.id,
|
||||
name: file.name,
|
||||
url: file.link || `/api/fileStorage/${file.realName}`,
|
||||
total: response.data.meta?.total || 0,
|
||||
realName: file.realName,
|
||||
}));
|
||||
this.total = response.data.meta?.totalPages;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error loading images:", error);
|
||||
this.list = [];
|
||||
}
|
||||
},
|
||||
async del({ name }: { name: string }) {
|
||||
await ApiFetch.api.img({ name }).delete();
|
||||
this.load();
|
||||
|
||||
async del({ id }: { id: string }) {
|
||||
try {
|
||||
await ApiFetch.api.fileStorage.delete({ id });
|
||||
await this.load({ page: this.page });
|
||||
} catch (error) {
|
||||
console.error("Error deleting image:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user