From bd21d18c21f5556bc8a307581bd26341ff74de8a Mon Sep 17 00:00:00 2001 From: phuongdm Date: Fri, 5 Jun 2026 20:23:14 +0700 Subject: [PATCH] =?UTF-8?q?gh=C3=A9p=20API=20sendManifest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/api.ts | 3 + src/hooks/queries/useAppVersionQueries.ts | 5 +- src/routes/_auth/apps/index.tsx | 25 ++--- src/services/app-version.service.ts | 13 +-- src/template/app-manager-template.tsx | 114 +++++++++++++++------- 5 files changed, 97 insertions(+), 63 deletions(-) diff --git a/src/config/api.ts b/src/config/api.ts index 046f4d4..7d8d4a9 100644 --- a/src/config/api.ts +++ b/src/config/api.ts @@ -74,6 +74,9 @@ export const API_ENDPOINTS = { DELETE_REQUIRED_FILE: `${BASE_URL}/AppVersion/requirefile/delete`, DELETE_FILES: `${BASE_URL}/AppVersion/delete`, }, + MANIFEST: { + SEND_ALL: `${BASE_URL}/Manifest/sendall`, + }, DEVICE_COMM: { DOWNLOAD_FILES: (roomName: string) => `${BASE_URL}/DeviceComm/downloadfile/${roomName}`, INSTALL_MSI: (roomName: string) => `${BASE_URL}/DeviceComm/installmsi/${roomName}`, diff --git a/src/hooks/queries/useAppVersionQueries.ts b/src/hooks/queries/useAppVersionQueries.ts index e0f2cd6..0128b93 100644 --- a/src/hooks/queries/useAppVersionQueries.ts +++ b/src/hooks/queries/useAppVersionQueries.ts @@ -186,11 +186,10 @@ export function useDeleteFile() { } /** - * Hook để gửi manifest [MOCK] + * Hook để gửi manifest */ export function useSendManifest() { return useMutation({ - mutationFn: (data: { targets: string[]; MsiFileIds: number[] }) => - appVersionService.sendManifest(data), + mutationFn: () => appVersionService.sendManifest(), }); } diff --git a/src/routes/_auth/apps/index.tsx b/src/routes/_auth/apps/index.tsx index 0877a93..4320e24 100644 --- a/src/routes/_auth/apps/index.tsx +++ b/src/routes/_auth/apps/index.tsx @@ -191,23 +191,16 @@ function AppsComponent() { } }; - const handleSendManifest = async (roomNames: string[]) => { - if (!table) { - toast.error("Không thể lấy thông tin bảng!"); - return; - } - - const selectedRows = table.getSelectedRowModel().rows; - if (selectedRows.length === 0) { - toast.error("Vui lòng chọn ít nhất một file để gửi manifest!"); - return; - } - - const MsiFileIds = selectedRows.map((row: any) => row.original.id); - + const handleSendManifest = async (targets: string[]) => { + // targets ignored for now — API sendall broadcasts to all devices via MQTT + // TODO: use targets when per-room/per-device manifest API is available try { - await sendManifestMutation.mutateAsync({ targets: roomNames, MsiFileIds }); - toast.success("Đã gửi manifest cho các phòng đã chọn!"); + await sendManifestMutation.mutateAsync(); + toast.success( + targets.length > 0 + ? `Đã gửi manifest cho ${targets.length} mục!` + : "Đã gửi manifest đến tất cả thiết bị!" + ); } catch (e) { toast.error("Gửi manifest thất bại!"); } diff --git a/src/services/app-version.service.ts b/src/services/app-version.service.ts index 174bd9b..e914167 100644 --- a/src/services/app-version.service.ts +++ b/src/services/app-version.service.ts @@ -131,14 +131,9 @@ export async function deleteFile(data: { MsiFileIds: number[] }): Promise<{ mess } /** - * [MOCK] Gửi manifest đến các phòng/thiết bị - * @param data - { targets: string[]; MsiFileIds: number[] } + * Gửi manifest (build + publish MQTT tới tất cả required files) */ -export async function sendManifest(data: { - targets: string[]; - MsiFileIds: number[]; -}): Promise<{ message: string }> { - // TODO: replace with real endpoint - await new Promise((resolve) => setTimeout(resolve, 800)); - return { message: `[MOCK] Manifest sent to ${data.targets.join(", ")}` }; +export async function sendManifest(): Promise<{ status: string; message: string }> { + const response = await axios.post(API_ENDPOINTS.MANIFEST.SEND_ALL); + return response.data; } diff --git a/src/template/app-manager-template.tsx b/src/template/app-manager-template.tsx index 911839c..f5cf2a7 100644 --- a/src/template/app-manager-template.tsx +++ b/src/template/app-manager-template.tsx @@ -82,7 +82,7 @@ export function AppManagerTemplate({ pageSizeOptions = [5, 10, 15, 20], }: AppManagerTemplateProps) { const [dialogOpen, setDialogOpen] = useState(false); - const [dialogType, setDialogType] = useState<"room" | "device" | "download-room" | "download-device" | "manifest-room" | null>(null); + const [dialogType, setDialogType] = useState<"room" | "device" | "download-room" | "download-device" | "manifest-room" | "manifest-device" | null>(null); const sortedData = useMemo(() => { const firstItem = data?.[0] as { fileName?: string } | undefined; @@ -128,6 +128,7 @@ export function AppManagerTemplate({ } }; + const openManifestRoomDialog = () => { if (rooms.length > 0 && onSendManifest) { setDialogType("manifest-room"); @@ -135,6 +136,18 @@ export function AppManagerTemplate({ } }; + const openManifestDeviceDialog = () => { + if (onSendManifest) { + setDialogType("manifest-device"); + setDialogOpen(true); + } + }; + + const handleManifestAll = async () => { + if (!onSendManifest) return; + await onSendManifest([]); + }; + const handleUpdateAll = async () => { if (!onUpdate) return; try { @@ -229,14 +242,16 @@ export function AppManagerTemplate({ )} {onSendManifest && ( - + )} {onDeleteFromServer && onDeleteFromRequired && ( @@ -336,33 +351,8 @@ export function AppManagerTemplate({ /> )} - {/* Dialog gửi manifest - chọn phòng */} - {dialogType === "manifest-room" && ( - { - setDialogOpen(false); - setDialogType(null); - }} - title="Chọn phòng" - description="Chọn các phòng để gửi manifest" - icon={} - items={mapRoomsToSelectItems(rooms)} - onConfirm={async (selectedItems) => { - if (!onSendManifest) return; - try { - await onSendManifest(selectedItems); - } catch (e) { - console.error("Send manifest error:", e); - } finally { - setDialogOpen(false); - setDialogType(null); - } - }} - /> - )} - {/* Dialog tải file - tìm thiết bị */} +{/* Dialog tải file - tìm thiết bị */} {dialogType === "download-device" && ( ({ }} /> )} + + {/* Dialog gửi manifest - chọn phòng */} + {dialogType === "manifest-room" && ( + { + setDialogOpen(false); + setDialogType(null); + }} + title="Chọn phòng" + description="Chọn các phòng để gửi manifest" + icon={} + items={mapRoomsToSelectItems(rooms)} + onConfirm={async (selectedItems) => { + if (!onSendManifest) return; + try { + await onSendManifest(selectedItems); + } catch (e) { + console.error("Send manifest error:", e); + } finally { + setDialogOpen(false); + setDialogType(null); + } + }} + /> + )} + + {/* Dialog gửi manifest - chọn thiết bị */} + {dialogType === "manifest-device" && ( + { + setDialogOpen(false); + setDialogType(null); + }} + rooms={rooms} + fetchDevices={getDeviceFromRoom} + onSelect={async (deviceIds) => { + if (!onSendManifest) { + setDialogOpen(false); + setDialogType(null); + return; + } + try { + await onSendManifest(deviceIds); + } catch (e) { + console.error("Send manifest error:", e); + } finally { + setDialogOpen(false); + setDialogType(null); + } + }} + /> + )} ); }