wcz-test 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +114 -9
- package/dist/index.js +205 -25
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ import * as _tanstack_form_core from '@tanstack/form-core';
|
|
|
16
16
|
export { useDialogs } from '@toolpad/core/useDialogs';
|
|
17
17
|
export { useNotifications } from '@toolpad/core/useNotifications';
|
|
18
18
|
export { useLocalStorageState } from '@toolpad/core/useLocalStorageState';
|
|
19
|
+
export { useTranslation } from 'react-i18next';
|
|
20
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
21
|
+
import { DefinedInitialDataOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
22
|
+
import { DetailedError } from 'tus-js-client';
|
|
19
23
|
|
|
20
24
|
interface TypographyWithIconProps extends TypographyProps {
|
|
21
25
|
startIcon?: React.ReactNode;
|
|
@@ -69,7 +73,6 @@ interface NavigationParams {
|
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
interface ProvidersProps {
|
|
72
|
-
title: string;
|
|
73
76
|
getNavigation?: (params: NavigationParams) => Navigation;
|
|
74
77
|
theme?: Pick<CssVarsThemeOptions, 'colorSchemes' | 'components'>;
|
|
75
78
|
children: React.ReactNode;
|
|
@@ -83,15 +86,11 @@ declare class Platform {
|
|
|
83
86
|
static readonly isMacOS: boolean;
|
|
84
87
|
}
|
|
85
88
|
declare const getContrastTextColor: (color: string) => "black" | "white";
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
declare const WISTRON_SECONDARY_COLOR = "#64DC00";
|
|
89
|
-
|
|
90
|
-
interface HeadProps {
|
|
91
|
-
name: string;
|
|
89
|
+
interface RootRouteHeadProps {
|
|
90
|
+
title: string;
|
|
92
91
|
themeColor: string;
|
|
93
92
|
}
|
|
94
|
-
declare const
|
|
93
|
+
declare const rootRouteHead: ({ title, themeColor }: RootRouteHeadProps) => () => {
|
|
95
94
|
meta: ({
|
|
96
95
|
charSet: string;
|
|
97
96
|
name?: undefined;
|
|
@@ -138,6 +137,9 @@ declare const defaultHead: ({ name, themeColor }: HeadProps) => () => {
|
|
|
138
137
|
theme_color?: undefined;
|
|
139
138
|
})[];
|
|
140
139
|
};
|
|
140
|
+
declare const wczApiClient: axios.AxiosInstance;
|
|
141
|
+
declare const WISTRON_PRIMARY_COLOR = "#00506E";
|
|
142
|
+
declare const WISTRON_SECONDARY_COLOR = "#64DC00";
|
|
141
143
|
|
|
142
144
|
type FormOmittedProps = "name" | "value" | "onChange" | "onBlur" | "error" | "helperText" | "renderInput" | "type" | "aria-label";
|
|
143
145
|
|
|
@@ -237,4 +239,107 @@ declare const withLayoutForm: <TFormData, TOnMount extends _tanstack_form_core.F
|
|
|
237
239
|
};
|
|
238
240
|
}>) => react.JSX.Element;
|
|
239
241
|
|
|
240
|
-
|
|
242
|
+
interface FileMeta {
|
|
243
|
+
id: string;
|
|
244
|
+
subId: string;
|
|
245
|
+
appName: string;
|
|
246
|
+
fileName: string;
|
|
247
|
+
fileExtension: string;
|
|
248
|
+
fileSize: number;
|
|
249
|
+
mediaSubType: string;
|
|
250
|
+
mediaType: string;
|
|
251
|
+
mimeType: string;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare const useGetFileMetas: (subId: string | undefined | null, options?: Omit<DefinedInitialDataOptions<FileMeta[]>, "queryKey" | "queryFn" | "initialData" | "refetchOnWindowFocus">) => _tanstack_react_query.DefinedUseQueryResult<FileMeta[], Error>;
|
|
255
|
+
declare const useGetFileThumbnail: (meta: FileMeta | undefined | null, options?: Omit<DefinedInitialDataOptions<Blob, Error, string>, "queryKey" | "queryFn" | "select" | "staleTime" | "gcTime" | "refetchOnWindowFocus" | "initialData">) => _tanstack_react_query.UseQueryResult<string, Error>;
|
|
256
|
+
declare const useGetFile: (meta: FileMeta | undefined | null, options?: Omit<DefinedInitialDataOptions<Blob, Error, string>, "queryKey" | "queryFn" | "select" | "staleTime" | "gcTime" | "refetchOnWindowFocus" | "initialData">) => _tanstack_react_query.UseQueryResult<string, Error>;
|
|
257
|
+
declare const useDownloadFile: (options?: Omit<UseMutationOptions<Blob, Error, FileMeta>, "mutationFn" | "onSuccess">) => _tanstack_react_query.UseMutationResult<Blob, Error, FileMeta, unknown>;
|
|
258
|
+
declare const useOpenFile: (options?: Omit<UseMutationOptions<Blob, Error, FileMeta>, "mutationFn" | "onSuccess">) => _tanstack_react_query.UseMutationResult<Blob, Error, FileMeta, unknown>;
|
|
259
|
+
declare const useUpdateFileMeta: (options?: Omit<UseMutationOptions<FileMeta, Error, FileMeta>, "mutationFn" | "onSettled">) => _tanstack_react_query.UseMutationResult<FileMeta, Error, FileMeta, unknown>;
|
|
260
|
+
declare const useDeleteFile: (options?: Omit<UseMutationOptions<FileMeta, Error, FileMeta>, "mutationFn" | "onSettled">) => _tanstack_react_query.UseMutationResult<FileMeta, Error, FileMeta, unknown>;
|
|
261
|
+
declare const useDeleteFiles: (options?: Omit<UseMutationOptions<string, Error, string>, "mutationFn" | "onSettled">) => _tanstack_react_query.UseMutationResult<string, Error, string, unknown>;
|
|
262
|
+
interface UseUploadFileProps {
|
|
263
|
+
subId: string | undefined | null;
|
|
264
|
+
onSuccess?: (file: File) => void;
|
|
265
|
+
onError?: (error: Error | DetailedError) => void;
|
|
266
|
+
}
|
|
267
|
+
declare const useUploadFile: ({ subId, onSuccess, onError }: UseUploadFileProps) => {
|
|
268
|
+
mutate: (file: File) => Promise<void>;
|
|
269
|
+
uploadProgress: number;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
interface EmailAttachment {
|
|
273
|
+
appName: string;
|
|
274
|
+
subId: string;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interface Email {
|
|
278
|
+
subject: string;
|
|
279
|
+
body: string;
|
|
280
|
+
to: string[];
|
|
281
|
+
bcc?: string[];
|
|
282
|
+
cc?: string[];
|
|
283
|
+
attachments?: EmailAttachment[];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
declare enum EmployeeCategoryGroup {
|
|
287
|
+
IDL = "IDL",
|
|
288
|
+
FD = "FD",
|
|
289
|
+
FI = "FI"
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
declare enum EmployeeStatus {
|
|
293
|
+
Active = "Active",
|
|
294
|
+
Terminated = "Terminated",
|
|
295
|
+
LeaveOfAbsence = "LeaveOfAbsence"
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
interface PeoplesoftEmployee {
|
|
299
|
+
badgeId: string;
|
|
300
|
+
category: string;
|
|
301
|
+
categoryGroup: EmployeeCategoryGroup;
|
|
302
|
+
companyCode: string;
|
|
303
|
+
contactPhone: string;
|
|
304
|
+
departmentId: string;
|
|
305
|
+
departmentDescription: string;
|
|
306
|
+
emailString: string;
|
|
307
|
+
employeeId: string;
|
|
308
|
+
extensionNumber: string;
|
|
309
|
+
firstName: string;
|
|
310
|
+
gender: string;
|
|
311
|
+
hiredDate: Date;
|
|
312
|
+
lastName: string;
|
|
313
|
+
managerId: string;
|
|
314
|
+
middleName: string;
|
|
315
|
+
name: string;
|
|
316
|
+
nameTitleCase: string;
|
|
317
|
+
nfcSn: string;
|
|
318
|
+
plantId: string;
|
|
319
|
+
position: string;
|
|
320
|
+
previousEmployeeIds: string | null;
|
|
321
|
+
reHiredDate: Date | null;
|
|
322
|
+
recordNumber: number;
|
|
323
|
+
status: EmployeeStatus;
|
|
324
|
+
supervisorId: string;
|
|
325
|
+
terminationDate: Date | null;
|
|
326
|
+
terminationFutureDate: Date | null;
|
|
327
|
+
type: string;
|
|
328
|
+
upperDepartmentId: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface PeoplesoftDepartment {
|
|
332
|
+
departmentId: string;
|
|
333
|
+
description: string;
|
|
334
|
+
managerId: string;
|
|
335
|
+
managerRecordNumber: string;
|
|
336
|
+
treeLevel: number;
|
|
337
|
+
upperDepartmentId: string;
|
|
338
|
+
companyCode: string;
|
|
339
|
+
location: string;
|
|
340
|
+
salLocation: string;
|
|
341
|
+
plantId: string;
|
|
342
|
+
manager: PeoplesoftEmployee;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export { ChipInputCell, EditableColumnHeader, type Email, type EmailAttachment, EmployeeCategoryGroup, EmployeeStatus, type FileMeta, LayoutProvider, type NavigationParams, type PeoplesoftDepartment, type PeoplesoftEmployee, Platform, RouterButton, RouterError, RouterLink, RouterNotFound, RouterTab, TypographyWithIcon, type User, WISTRON_PRIMARY_COLOR, WISTRON_SECONDARY_COLOR, getContrastTextColor, rootRouteHead, useDeleteFile, useDeleteFiles, useDownloadFile, useFieldContext, useFormContext, useGetFile, useGetFileMetas, useGetFileThumbnail, useLayoutForm, useOpenFile, useUpdateFileMeta, useUploadFile, wczApiClient, withLayoutForm };
|
package/dist/index.js
CHANGED
|
@@ -1780,6 +1780,7 @@ var AdapterDayjs = class {
|
|
|
1780
1780
|
|
|
1781
1781
|
// src/providers/LayoutProvider.tsx
|
|
1782
1782
|
import { useIsFetching, useIsMutating } from "@tanstack/react-query";
|
|
1783
|
+
import { useRouterState } from "@tanstack/react-router";
|
|
1783
1784
|
import { DashboardLayout } from "@toolpad/core/DashboardLayout";
|
|
1784
1785
|
import { NotificationsProvider } from "@toolpad/core/useNotifications";
|
|
1785
1786
|
import i18n from "i18next";
|
|
@@ -1793,11 +1794,19 @@ import zodEnTranslations from "zod-i18n-map/locales/en/zod.json";
|
|
|
1793
1794
|
|
|
1794
1795
|
// src/components/core/AppTitle.tsx
|
|
1795
1796
|
import { Stack as Stack3, Typography as Typography4 } from "@mui/material";
|
|
1797
|
+
|
|
1798
|
+
// src/contexts/LayoutContext.ts
|
|
1799
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
1800
|
+
var LayoutContext = createContext2({});
|
|
1801
|
+
var useLayout = () => useContext2(LayoutContext);
|
|
1802
|
+
|
|
1803
|
+
// src/components/core/AppTitle.tsx
|
|
1796
1804
|
import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1797
|
-
var AppTitle = (
|
|
1805
|
+
var AppTitle = () => {
|
|
1806
|
+
const { appTitle } = useLayout();
|
|
1798
1807
|
return /* @__PURE__ */ jsxs4(Stack3, { direction: "row", alignItems: "center", spacing: 2, children: [
|
|
1799
1808
|
/* @__PURE__ */ jsx9("img", { src: "/favicon-32x32.png", alt: "app-logo", loading: "lazy" }),
|
|
1800
|
-
/* @__PURE__ */ jsx9(Typography4, { variant: "h6", children:
|
|
1809
|
+
/* @__PURE__ */ jsx9(Typography4, { variant: "h6", children: appTitle })
|
|
1801
1810
|
] });
|
|
1802
1811
|
};
|
|
1803
1812
|
|
|
@@ -2044,6 +2053,23 @@ var getContrastTextColor = (color) => {
|
|
|
2044
2053
|
const yiq = (r * 299 + g * 587 + b * 114) / 1e3;
|
|
2045
2054
|
return yiq >= 128 ? "black" : "white";
|
|
2046
2055
|
};
|
|
2056
|
+
var rootRouteHead = ({ title, themeColor }) => () => ({
|
|
2057
|
+
meta: [
|
|
2058
|
+
{ charSet: "utf-8" },
|
|
2059
|
+
{ name: "viewport", content: "width=device-width, initial-scale=1" },
|
|
2060
|
+
{ title },
|
|
2061
|
+
{ name: "og:type", content: "website" },
|
|
2062
|
+
{ name: "og:title", content: title },
|
|
2063
|
+
{ name: "og:image", content: "/favicon-32x32.png" }
|
|
2064
|
+
],
|
|
2065
|
+
links: [
|
|
2066
|
+
{ rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" },
|
|
2067
|
+
{ rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png" },
|
|
2068
|
+
{ rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon-16x16.png" },
|
|
2069
|
+
{ rel: "manifest", href: "/site.webmanifest", name: title, theme_color: themeColor },
|
|
2070
|
+
{ rel: "icon", href: "/favicon.ico" }
|
|
2071
|
+
]
|
|
2072
|
+
});
|
|
2047
2073
|
var wczApiClient = axios.create();
|
|
2048
2074
|
wczApiClient.interceptors.request.use(async (config) => {
|
|
2049
2075
|
await UserService.updateToken();
|
|
@@ -2186,6 +2212,7 @@ i18n.addResourceBundle("en", "zod", zodEnTranslations);
|
|
|
2186
2212
|
i18n.addResourceBundle("cs", "zod", zodCsTranslations);
|
|
2187
2213
|
z.setErrorMap(zodI18nMap);
|
|
2188
2214
|
var LayoutProvider = (props) => {
|
|
2215
|
+
const rootRouterState = useRouterState({ select: (s) => s.matches[0] });
|
|
2189
2216
|
const theme = useGetTheme(props.theme);
|
|
2190
2217
|
const { t, i18n: i18n2 } = useTranslation5();
|
|
2191
2218
|
const isFetching = !!useIsFetching();
|
|
@@ -2193,7 +2220,10 @@ var LayoutProvider = (props) => {
|
|
|
2193
2220
|
const isLargeScreen = useMediaQuery(theme.breakpoints.up("sm"));
|
|
2194
2221
|
const user2 = { name: "Dalibor", department: "MD0L50", employeeId: "C2503017", company: "", category: "" };
|
|
2195
2222
|
const navigation = props.getNavigation ? props.getNavigation({ user: user2, t }) : [];
|
|
2196
|
-
|
|
2223
|
+
const appTitle = rootRouterState.meta?.find((meta) => meta?.title)?.title;
|
|
2224
|
+
if (!appTitle)
|
|
2225
|
+
throw new Error("Title is not defined in the RootRoute head.");
|
|
2226
|
+
return /* @__PURE__ */ jsx13(LocalizationProvider, { dateAdapter: AdapterDayjs, adapterLocale: i18n2.resolvedLanguage, children: /* @__PURE__ */ jsx13(TanstackRouterAppProvider, { navigation, theme, children: /* @__PURE__ */ jsx13(NotificationsProvider, { slotProps: { snackbar: { anchorOrigin: { vertical: isLargeScreen ? "top" : "bottom", horizontal: "center" } } }, children: /* @__PURE__ */ jsx13(LayoutContext.Provider, { value: { appTitle }, children: /* @__PURE__ */ jsxs7(
|
|
2197
2227
|
DashboardLayout,
|
|
2198
2228
|
{
|
|
2199
2229
|
defaultSidebarCollapsed: true,
|
|
@@ -2201,7 +2231,7 @@ var LayoutProvider = (props) => {
|
|
|
2201
2231
|
slots: {
|
|
2202
2232
|
toolbarActions: () => null,
|
|
2203
2233
|
toolbarAccount: ToolbarAccount,
|
|
2204
|
-
appTitle:
|
|
2234
|
+
appTitle: AppTitle
|
|
2205
2235
|
},
|
|
2206
2236
|
children: [
|
|
2207
2237
|
props.children,
|
|
@@ -2209,31 +2239,12 @@ var LayoutProvider = (props) => {
|
|
|
2209
2239
|
(isFetching || isMutating) && /* @__PURE__ */ jsx13(LinearProgress, { sx: { position: "fixed", top: { xs: 56, sm: 64 }, left: 0, right: 0 } })
|
|
2210
2240
|
]
|
|
2211
2241
|
}
|
|
2212
|
-
) }) }) });
|
|
2242
|
+
) }) }) }) });
|
|
2213
2243
|
};
|
|
2214
2244
|
|
|
2215
2245
|
// src/index.ts
|
|
2216
2246
|
import { uuidv7 } from "uuidv7";
|
|
2217
2247
|
|
|
2218
|
-
// src/utils/client/DefaultHead.ts
|
|
2219
|
-
var defaultHead = ({ name, themeColor }) => () => ({
|
|
2220
|
-
meta: [
|
|
2221
|
-
{ charSet: "utf-8" },
|
|
2222
|
-
{ name: "viewport", content: "width=device-width, initial-scale=1" },
|
|
2223
|
-
{ title: name },
|
|
2224
|
-
{ name: "og:type", content: "website" },
|
|
2225
|
-
{ name: "og:title", content: name },
|
|
2226
|
-
{ name: "og:image", content: "/favicon-32x32.png" }
|
|
2227
|
-
],
|
|
2228
|
-
links: [
|
|
2229
|
-
{ rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" },
|
|
2230
|
-
{ rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png" },
|
|
2231
|
-
{ rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon-16x16.png" },
|
|
2232
|
-
{ rel: "manifest", href: "/site.webmanifest", name, theme_color: themeColor },
|
|
2233
|
-
{ rel: "icon", href: "/favicon.ico" }
|
|
2234
|
-
]
|
|
2235
|
-
});
|
|
2236
|
-
|
|
2237
2248
|
// src/hooks/FormHooks.ts
|
|
2238
2249
|
import { createFormHook, createFormHookContexts } from "@tanstack/react-form";
|
|
2239
2250
|
|
|
@@ -2537,6 +2548,165 @@ var { useAppForm: useLayoutForm, withForm: withLayoutForm } = createFormHook({
|
|
|
2537
2548
|
import { useDialogs } from "@toolpad/core/useDialogs";
|
|
2538
2549
|
import { useNotifications } from "@toolpad/core/useNotifications";
|
|
2539
2550
|
import { useLocalStorageState } from "@toolpad/core/useLocalStorageState";
|
|
2551
|
+
import { useTranslation as useTranslation6 } from "react-i18next";
|
|
2552
|
+
|
|
2553
|
+
// src/hooks/FileHooks.ts
|
|
2554
|
+
import { useMutation, useQuery, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
2555
|
+
import saveAs from "file-saver";
|
|
2556
|
+
import { useState as useState3 } from "react";
|
|
2557
|
+
import { Upload as TusUpload } from "tus-js-client";
|
|
2558
|
+
var BASE_URL = import.meta.env.VITE_FILE_API_BASE_URL;
|
|
2559
|
+
var QUERY_KEY = "Files";
|
|
2560
|
+
var HOUR = 1e3 * 60 * 60;
|
|
2561
|
+
var useGetFileMetas = (subId, options) => {
|
|
2562
|
+
const { appTitle } = useLayout();
|
|
2563
|
+
return useQuery({
|
|
2564
|
+
...options,
|
|
2565
|
+
queryKey: [QUERY_KEY, "meta", subId],
|
|
2566
|
+
queryFn: ({ signal }) => wczApiClient.request({
|
|
2567
|
+
url: `${BASE_URL}/v1/meta?appName=${appTitle}&subId=${subId}`,
|
|
2568
|
+
method: "GET",
|
|
2569
|
+
signal
|
|
2570
|
+
}),
|
|
2571
|
+
initialData: [],
|
|
2572
|
+
refetchOnWindowFocus: false
|
|
2573
|
+
});
|
|
2574
|
+
};
|
|
2575
|
+
var useGetFileThumbnail = (meta, options) => {
|
|
2576
|
+
const { appTitle } = useLayout();
|
|
2577
|
+
return useQuery({
|
|
2578
|
+
...options,
|
|
2579
|
+
queryKey: [QUERY_KEY, "thumbnail", meta?.id],
|
|
2580
|
+
queryFn: ({ signal }) => wczApiClient.request({
|
|
2581
|
+
url: `${BASE_URL}/v1/thumbnail?appName=${appTitle}&id=${meta?.id}`,
|
|
2582
|
+
method: "GET",
|
|
2583
|
+
signal,
|
|
2584
|
+
responseType: "blob"
|
|
2585
|
+
}),
|
|
2586
|
+
select: (data) => URL.createObjectURL(data),
|
|
2587
|
+
staleTime: HOUR,
|
|
2588
|
+
gcTime: HOUR,
|
|
2589
|
+
refetchOnWindowFocus: false,
|
|
2590
|
+
enabled: !!meta?.id && options?.enabled
|
|
2591
|
+
});
|
|
2592
|
+
};
|
|
2593
|
+
var useGetFile = (meta, options) => {
|
|
2594
|
+
const { appTitle } = useLayout();
|
|
2595
|
+
return useQuery({
|
|
2596
|
+
...options,
|
|
2597
|
+
queryKey: [QUERY_KEY, meta?.id],
|
|
2598
|
+
queryFn: ({ signal }) => wczApiClient.request({
|
|
2599
|
+
url: `${BASE_URL}/v1?appName=${appTitle}&id=${meta?.id}`,
|
|
2600
|
+
method: "GET",
|
|
2601
|
+
signal,
|
|
2602
|
+
responseType: "blob"
|
|
2603
|
+
}),
|
|
2604
|
+
select: (data) => URL.createObjectURL(data),
|
|
2605
|
+
staleTime: HOUR,
|
|
2606
|
+
gcTime: HOUR,
|
|
2607
|
+
refetchOnWindowFocus: false,
|
|
2608
|
+
enabled: !!meta?.id && options?.enabled
|
|
2609
|
+
});
|
|
2610
|
+
};
|
|
2611
|
+
var useDownloadFile = (options) => {
|
|
2612
|
+
const { appTitle } = useLayout();
|
|
2613
|
+
return useMutation({
|
|
2614
|
+
...options,
|
|
2615
|
+
mutationFn: (meta) => wczApiClient.request({
|
|
2616
|
+
url: `${BASE_URL}/v1/download?appName=${appTitle}&id=${meta.id}`,
|
|
2617
|
+
method: "GET",
|
|
2618
|
+
responseType: "blob"
|
|
2619
|
+
}),
|
|
2620
|
+
onSuccess: (data, variables) => saveAs(data, `${variables.fileName}.${variables.fileExtension}`)
|
|
2621
|
+
});
|
|
2622
|
+
};
|
|
2623
|
+
var useOpenFile = (options) => {
|
|
2624
|
+
const { appTitle } = useLayout();
|
|
2625
|
+
return useMutation({
|
|
2626
|
+
...options,
|
|
2627
|
+
mutationFn: (meta) => wczApiClient.request({
|
|
2628
|
+
url: `${BASE_URL}/v1?appName=${appTitle}&id=${meta.id}`,
|
|
2629
|
+
method: "GET",
|
|
2630
|
+
responseType: "blob"
|
|
2631
|
+
}),
|
|
2632
|
+
onSuccess: (data) => window.open(URL.createObjectURL(data))
|
|
2633
|
+
});
|
|
2634
|
+
};
|
|
2635
|
+
var useUpdateFileMeta = (options) => {
|
|
2636
|
+
const { appTitle } = useLayout();
|
|
2637
|
+
const queryClient = useQueryClient2();
|
|
2638
|
+
return useMutation({
|
|
2639
|
+
...options,
|
|
2640
|
+
mutationFn: (meta) => wczApiClient.request({
|
|
2641
|
+
url: `${BASE_URL}/v1/meta?appName=${appTitle}&id=${meta.id}`,
|
|
2642
|
+
method: "PUT",
|
|
2643
|
+
data: meta
|
|
2644
|
+
}),
|
|
2645
|
+
onSettled: () => queryClient.invalidateQueries({ queryKey: [QUERY_KEY, "meta"], exact: false })
|
|
2646
|
+
});
|
|
2647
|
+
};
|
|
2648
|
+
var useDeleteFile = (options) => {
|
|
2649
|
+
const { appTitle } = useLayout();
|
|
2650
|
+
const queryClient = useQueryClient2();
|
|
2651
|
+
return useMutation({
|
|
2652
|
+
...options,
|
|
2653
|
+
mutationFn: (meta) => wczApiClient.request({
|
|
2654
|
+
url: `${BASE_URL}/v1?appName=${appTitle}&id=${meta.id}`,
|
|
2655
|
+
method: "DELETE"
|
|
2656
|
+
}),
|
|
2657
|
+
onSettled: () => queryClient.invalidateQueries({ queryKey: [QUERY_KEY, "meta"], exact: false })
|
|
2658
|
+
});
|
|
2659
|
+
};
|
|
2660
|
+
var useDeleteFiles = (options) => {
|
|
2661
|
+
const { appTitle } = useLayout();
|
|
2662
|
+
const queryClient = useQueryClient2();
|
|
2663
|
+
return useMutation({
|
|
2664
|
+
...options,
|
|
2665
|
+
mutationFn: (subId) => wczApiClient.request({
|
|
2666
|
+
url: `${BASE_URL}/v1?appName=${appTitle}&subId=${subId}`,
|
|
2667
|
+
method: "DELETE"
|
|
2668
|
+
}),
|
|
2669
|
+
onSettled: () => queryClient.invalidateQueries({ queryKey: [QUERY_KEY, "meta"], exact: false })
|
|
2670
|
+
});
|
|
2671
|
+
};
|
|
2672
|
+
var useUploadFile = ({ subId, onSuccess, onError }) => {
|
|
2673
|
+
const { appTitle } = useLayout();
|
|
2674
|
+
const [uploadProgress, setUploadProgress] = useState3(0);
|
|
2675
|
+
const queryClient = useQueryClient2();
|
|
2676
|
+
const mutate = async (file) => {
|
|
2677
|
+
if (!subId) throw new Error("subId is required for file upload");
|
|
2678
|
+
const upload = new TusUpload(file, {
|
|
2679
|
+
endpoint: `${BASE_URL}/v1/upload`,
|
|
2680
|
+
chunkSize: 1048576,
|
|
2681
|
+
// 1 MB
|
|
2682
|
+
metadata: {
|
|
2683
|
+
appName: appTitle,
|
|
2684
|
+
subId,
|
|
2685
|
+
filename: file.name,
|
|
2686
|
+
filetype: file.type
|
|
2687
|
+
},
|
|
2688
|
+
//headers: { "Authorization": `Bearer ${await getToken()}` }, //TODO: implement token retrieval
|
|
2689
|
+
onError: (error) => {
|
|
2690
|
+
setUploadProgress(0);
|
|
2691
|
+
onError?.(error);
|
|
2692
|
+
},
|
|
2693
|
+
onProgress: (bytesUploaded, bytesTotal) => {
|
|
2694
|
+
setUploadProgress(bytesUploaded / bytesTotal * 100);
|
|
2695
|
+
},
|
|
2696
|
+
onSuccess: () => {
|
|
2697
|
+
setUploadProgress(0);
|
|
2698
|
+
queryClient.invalidateQueries({ queryKey: [QUERY_KEY, "meta"], exact: false });
|
|
2699
|
+
onSuccess?.(file);
|
|
2700
|
+
}
|
|
2701
|
+
});
|
|
2702
|
+
const previousUploads = await upload.findPreviousUploads();
|
|
2703
|
+
if (previousUploads.length) {
|
|
2704
|
+
upload.resumeFromPreviousUpload(previousUploads[0]);
|
|
2705
|
+
}
|
|
2706
|
+
upload.start();
|
|
2707
|
+
};
|
|
2708
|
+
return { mutate, uploadProgress };
|
|
2709
|
+
};
|
|
2540
2710
|
export {
|
|
2541
2711
|
ChipInputCell,
|
|
2542
2712
|
EditableColumnHeader,
|
|
@@ -2550,14 +2720,24 @@ export {
|
|
|
2550
2720
|
TypographyWithIcon,
|
|
2551
2721
|
WISTRON_PRIMARY_COLOR,
|
|
2552
2722
|
WISTRON_SECONDARY_COLOR,
|
|
2553
|
-
defaultHead,
|
|
2554
2723
|
getContrastTextColor,
|
|
2724
|
+
rootRouteHead,
|
|
2725
|
+
useDeleteFile,
|
|
2726
|
+
useDeleteFiles,
|
|
2555
2727
|
useDialogs,
|
|
2728
|
+
useDownloadFile,
|
|
2556
2729
|
useFieldContext,
|
|
2557
2730
|
useFormContext,
|
|
2731
|
+
useGetFile,
|
|
2732
|
+
useGetFileMetas,
|
|
2733
|
+
useGetFileThumbnail,
|
|
2558
2734
|
useLayoutForm,
|
|
2559
2735
|
useLocalStorageState,
|
|
2560
2736
|
useNotifications,
|
|
2737
|
+
useOpenFile,
|
|
2738
|
+
useTranslation6 as useTranslation,
|
|
2739
|
+
useUpdateFileMeta,
|
|
2740
|
+
useUploadFile,
|
|
2561
2741
|
uuidv7,
|
|
2562
2742
|
wczApiClient,
|
|
2563
2743
|
withLayoutForm
|