2025-09-10 09:59:17 +07:00
|
|
|
import { type ColumnDef } from "@tanstack/react-table";
|
|
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardFooter,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from "@/components/ui/card";
|
|
|
|
|
import { FileText } from "lucide-react";
|
|
|
|
|
import { UploadDialog } from "@/components/upload-dialog";
|
|
|
|
|
import { VersionTable } from "@/components/version-table";
|
|
|
|
|
import { UpdateButton } from "@/components/update-button";
|
2025-09-26 17:56:55 +07:00
|
|
|
import { RoomSelectDialog } from "@/components/room-select-dialog";
|
2025-09-24 16:13:57 +07:00
|
|
|
import type { AxiosProgressEvent } from "axios";
|
2025-09-26 17:56:55 +07:00
|
|
|
import { useState } from "react";
|
2025-09-10 09:59:17 +07:00
|
|
|
|
|
|
|
|
interface AppManagerTemplateProps<TData> {
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
data: TData[];
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
columns: ColumnDef<TData, any>[];
|
2025-09-26 17:56:55 +07:00
|
|
|
onUpload: (
|
|
|
|
|
fd: FormData,
|
|
|
|
|
config?: { onUploadProgress?: (e: AxiosProgressEvent) => void }
|
|
|
|
|
) => Promise<void>;
|
|
|
|
|
onUpdate?: (roomName: string) => void;
|
2025-09-10 09:59:17 +07:00
|
|
|
updateLoading?: boolean;
|
|
|
|
|
onTableInit?: (table: any) => void;
|
2025-09-26 17:56:55 +07:00
|
|
|
rooms: string[];
|
2025-09-10 09:59:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function AppManagerTemplate<TData>({
|
|
|
|
|
title,
|
|
|
|
|
description,
|
|
|
|
|
data,
|
|
|
|
|
isLoading,
|
|
|
|
|
columns,
|
|
|
|
|
onUpload,
|
|
|
|
|
onUpdate,
|
|
|
|
|
updateLoading,
|
|
|
|
|
onTableInit,
|
2025-09-26 17:56:55 +07:00
|
|
|
rooms,
|
2025-09-10 09:59:17 +07:00
|
|
|
}: AppManagerTemplateProps<TData>) {
|
2025-09-26 17:56:55 +07:00
|
|
|
const [dialogOpen, setDialogOpen] = useState(false);
|
|
|
|
|
const handleUpdateClick = () => {
|
|
|
|
|
if (rooms && onUpdate) {
|
|
|
|
|
setDialogOpen(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-09-10 09:59:17 +07:00
|
|
|
return (
|
|
|
|
|
<div className="w-full px-6 space-y-4">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div>
|
|
|
|
|
<h1 className="text-3xl font-bold">{title}</h1>
|
|
|
|
|
<p className="text-muted-foreground mt-2">{description}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<UploadDialog onSubmit={onUpload} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Card className="w-full">
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="flex items-center gap-2">
|
|
|
|
|
<FileText className="h-5 w-5" /> Lịch sử phiên bản
|
|
|
|
|
</CardTitle>
|
|
|
|
|
<CardDescription>Tất cả các phiên bản đã tải lên</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
<VersionTable
|
|
|
|
|
data={data}
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
columns={columns}
|
|
|
|
|
onTableInit={onTableInit}
|
|
|
|
|
/>
|
|
|
|
|
</CardContent>
|
|
|
|
|
{onUpdate && (
|
|
|
|
|
<CardFooter>
|
2025-09-26 17:56:55 +07:00
|
|
|
<UpdateButton onClick={handleUpdateClick} loading={updateLoading} />
|
|
|
|
|
<UpdateButton
|
|
|
|
|
onClick={() => onUpdate("All")}
|
|
|
|
|
loading={updateLoading}
|
|
|
|
|
label="Cập nhật tất cả thiết bị"
|
|
|
|
|
/>
|
2025-09-10 09:59:17 +07:00
|
|
|
</CardFooter>
|
|
|
|
|
)}
|
2025-09-26 17:56:55 +07:00
|
|
|
{rooms && onUpdate && (
|
|
|
|
|
<RoomSelectDialog
|
|
|
|
|
open={dialogOpen}
|
|
|
|
|
onClose={() => setDialogOpen(false)}
|
|
|
|
|
rooms={rooms}
|
|
|
|
|
onConfirm={(roomName) => {
|
|
|
|
|
onUpdate(roomName);
|
|
|
|
|
setDialogOpen(false);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-09-10 09:59:17 +07:00
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-09-26 17:56:55 +07:00
|
|
|
}
|