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