@appcorp/fusion-storybook 0.1.21 → 0.1.24
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/base-modules/teacher/cache.d.ts +14 -0
- package/base-modules/teacher/cache.js +31 -0
- package/base-modules/teacher/constants.d.ts +23 -0
- package/base-modules/teacher/constants.js +27 -0
- package/base-modules/teacher/context.d.ts +245 -0
- package/base-modules/teacher/context.js +461 -0
- package/base-modules/teacher/filter.d.ts +1 -0
- package/base-modules/teacher/filter.js +29 -0
- package/base-modules/teacher/form.d.ts +1 -0
- package/base-modules/teacher/form.js +30 -0
- package/base-modules/teacher/more-actions.d.ts +1 -0
- package/base-modules/teacher/more-actions.js +50 -0
- package/base-modules/teacher/page.d.ts +32 -0
- package/base-modules/teacher/page.js +141 -0
- package/base-modules/teacher/validate.d.ts +26 -0
- package/base-modules/teacher/validate.js +37 -0
- package/base-modules/teacher/view.d.ts +1 -0
- package/base-modules/teacher/view.js +27 -0
- package/base-modules/user/cache.d.ts +14 -0
- package/base-modules/user/cache.js +31 -0
- package/base-modules/user/constants.d.ts +9 -0
- package/base-modules/user/constants.js +19 -0
- package/base-modules/user/context.d.ts +218 -0
- package/base-modules/user/context.js +585 -0
- package/base-modules/user/drawer.d.ts +1 -0
- package/base-modules/user/drawer.js +25 -0
- package/base-modules/user/filter.d.ts +1 -0
- package/base-modules/user/filter.js +21 -0
- package/base-modules/user/form.d.ts +1 -0
- package/base-modules/user/form.js +28 -0
- package/base-modules/user/more-actions.d.ts +1 -0
- package/base-modules/user/more-actions.js +48 -0
- package/base-modules/user/page.d.ts +30 -0
- package/base-modules/user/page.js +120 -0
- package/base-modules/user/validate.d.ts +16 -0
- package/base-modules/user/validate.js +29 -0
- package/base-modules/user/view.d.ts +1 -0
- package/base-modules/user/view.js +24 -0
- package/base-modules/workspace-user/cache.d.ts +14 -0
- package/base-modules/workspace-user/cache.js +31 -0
- package/base-modules/workspace-user/constants.d.ts +21 -0
- package/base-modules/workspace-user/constants.js +27 -0
- package/base-modules/workspace-user/context.d.ts +155 -0
- package/base-modules/workspace-user/context.js +382 -0
- package/base-modules/workspace-user/filter.d.ts +1 -0
- package/base-modules/workspace-user/filter.js +23 -0
- package/base-modules/workspace-user/form.d.ts +1 -0
- package/base-modules/workspace-user/form.js +12 -0
- package/base-modules/workspace-user/more-actions.d.ts +1 -0
- package/base-modules/workspace-user/more-actions.js +51 -0
- package/base-modules/workspace-user/page.d.ts +28 -0
- package/base-modules/workspace-user/page.js +106 -0
- package/base-modules/workspace-user/validate.d.ts +12 -0
- package/base-modules/workspace-user/validate.js +15 -0
- package/base-modules/workspace-user/view.d.ts +1 -0
- package/base-modules/workspace-user/view.js +20 -0
- package/components/timeline.d.ts +11 -0
- package/components/timeline.js +4 -0
- package/package.json +4 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/toast-network-error.d.ts +1 -0
- package/utils/toast-network-error.js +7 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { downloadFromUrl, API_METHODS } from "@react-pakistan/util-functions";
|
|
4
|
+
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
5
|
+
import converter from "json-2-csv";
|
|
6
|
+
import { Timeline } from "../../components/timeline";
|
|
7
|
+
export const UserMoreActions = () => {
|
|
8
|
+
const workspace = getCachedWorkspaceSync();
|
|
9
|
+
const handleGetAllRecords = async (schoolId) => {
|
|
10
|
+
const response = await fetch(`/api/user?pageLimit=1000¤tPage=1&schoolId=${schoolId}`, { method: API_METHODS.GET });
|
|
11
|
+
const result = await response.json();
|
|
12
|
+
const csv = await converter.json2csv(result.items || [], {});
|
|
13
|
+
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
14
|
+
await downloadFromUrl(blob, "user.csv");
|
|
15
|
+
};
|
|
16
|
+
const create = [
|
|
17
|
+
{
|
|
18
|
+
id: "1",
|
|
19
|
+
title: "Download empty csv template",
|
|
20
|
+
handleOnClick: async () => {
|
|
21
|
+
await downloadFromUrl("https://nwolvgylwmjuqxsngjxt.supabase.co/storage/v1/object/public/public-blob/common-assets/user.csv", "user-template.csv");
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{ id: "2", title: "Add your data to the csv" },
|
|
25
|
+
{
|
|
26
|
+
id: "3",
|
|
27
|
+
title: "Upload the completed csv to the system",
|
|
28
|
+
handleOnClick: () => { },
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
const update = [
|
|
32
|
+
{
|
|
33
|
+
id: "1",
|
|
34
|
+
title: "Download populated csv template",
|
|
35
|
+
handleOnClick: async () => {
|
|
36
|
+
var _a;
|
|
37
|
+
await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "");
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{ id: "2", title: "Update your data to the csv" },
|
|
41
|
+
{
|
|
42
|
+
id: "3",
|
|
43
|
+
title: "Upload the completed csv to the system",
|
|
44
|
+
handleOnClick: () => { },
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Timeline, { events: create, heading: "Bulk Create" }), _jsx(Timeline, { events: update, heading: "Bulk Update" })] }));
|
|
48
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Page Component
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around GenericModulePage. All handlers, header actions, and row
|
|
5
|
+
* actions live in context.tsx — this file only owns:
|
|
6
|
+
* - tableBodyCols (static, module-level constant)
|
|
7
|
+
* - userConfig (memoised on locale change only; size fixed per drawer so
|
|
8
|
+
* the component type produced by createGenericModulePage never changes at
|
|
9
|
+
* runtime, preventing the infinite-remount re-render loop)
|
|
10
|
+
* - permission guard
|
|
11
|
+
*/
|
|
12
|
+
import { FC } from "react";
|
|
13
|
+
import { USER_ROLE } from "../../type";
|
|
14
|
+
interface UserPageProps {
|
|
15
|
+
cancelLabel: string;
|
|
16
|
+
drawerTitle: string;
|
|
17
|
+
labelActions: string;
|
|
18
|
+
labelEmail: string;
|
|
19
|
+
labelEnabled: string;
|
|
20
|
+
labelId: string;
|
|
21
|
+
labelName: string;
|
|
22
|
+
labelPhone: string;
|
|
23
|
+
saveLabel: string;
|
|
24
|
+
searchPlaceholder: string;
|
|
25
|
+
tableDescription: string;
|
|
26
|
+
tableTitle: string;
|
|
27
|
+
userRole: USER_ROLE;
|
|
28
|
+
}
|
|
29
|
+
export declare const UserPage: FC<UserPageProps>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* User Page Component
|
|
5
|
+
*
|
|
6
|
+
* Thin wrapper around GenericModulePage. All handlers, header actions, and row
|
|
7
|
+
* actions live in context.tsx — this file only owns:
|
|
8
|
+
* - tableBodyCols (static, module-level constant)
|
|
9
|
+
* - userConfig (memoised on locale change only; size fixed per drawer so
|
|
10
|
+
* the component type produced by createGenericModulePage never changes at
|
|
11
|
+
* runtime, preventing the infinite-remount re-render loop)
|
|
12
|
+
* - permission guard
|
|
13
|
+
*/
|
|
14
|
+
import { useMemo } from "react";
|
|
15
|
+
import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
|
|
16
|
+
import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
17
|
+
import { useUserModule, UserProvider, USER_DRAWER, USER_ACTION_TYPES, } from "./context";
|
|
18
|
+
import { UserFilter } from "./filter";
|
|
19
|
+
import { UserForm } from "./form";
|
|
20
|
+
import { UserView } from "./view";
|
|
21
|
+
import { UserMoreActions } from "./more-actions";
|
|
22
|
+
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
23
|
+
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// TABLE COLUMN CONFIGURATION (static — no runtime deps)
|
|
26
|
+
// ============================================================================
|
|
27
|
+
const tableBodyCols = [
|
|
28
|
+
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
29
|
+
{ componentType: COMPONENT_TYPE.TEXT, key: "name" },
|
|
30
|
+
{ componentType: COMPONENT_TYPE.TEXT, key: "email" },
|
|
31
|
+
{ componentType: COMPONENT_TYPE.TEXT, key: "phone" },
|
|
32
|
+
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
|
|
33
|
+
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
34
|
+
];
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// COMPONENT FACTORY (creates JSX elements when config is created, not during render)
|
|
37
|
+
// ============================================================================
|
|
38
|
+
const createComponentInstances = () => ({
|
|
39
|
+
filter: _jsx(UserFilter, {}),
|
|
40
|
+
form: _jsx(UserForm, {}),
|
|
41
|
+
moreActions: _jsx(UserMoreActions, {}),
|
|
42
|
+
view: _jsx(UserView, {}),
|
|
43
|
+
});
|
|
44
|
+
const createUserConfig = ({ cancelLabel, dispatch, drawer, drawerTitle, labelActions, labelEmail, labelEnabled, labelId, labelName, labelPhone, saveLabel, searchPlaceholder, tableDescription, tableTitle, }) => {
|
|
45
|
+
const components = createComponentInstances();
|
|
46
|
+
return {
|
|
47
|
+
moduleName: "user",
|
|
48
|
+
tableColumns: [
|
|
49
|
+
{ label: labelId, width: "5%" },
|
|
50
|
+
{ label: labelName, width: "30%" },
|
|
51
|
+
{ label: labelEmail, width: "30%" },
|
|
52
|
+
{ label: labelPhone, width: "20%" },
|
|
53
|
+
{ label: labelEnabled, width: "10%" },
|
|
54
|
+
{ label: labelActions, width: "5%" },
|
|
55
|
+
],
|
|
56
|
+
cancelLabel,
|
|
57
|
+
drawerTitle,
|
|
58
|
+
filterContent: components.filter,
|
|
59
|
+
formContent: components.form,
|
|
60
|
+
moreActionsContent: components.moreActions,
|
|
61
|
+
saveLabel,
|
|
62
|
+
searchPlaceholder,
|
|
63
|
+
tableDescription,
|
|
64
|
+
tableTitle,
|
|
65
|
+
viewContent: components.view,
|
|
66
|
+
size: drawer === USER_DRAWER.FORM_DRAWER ? "full" : "small",
|
|
67
|
+
onClearFilters: () => {
|
|
68
|
+
dispatch({ type: USER_ACTION_TYPES.RESET_FORM });
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// STABLE PAGE COMPONENT (created once, outside render)
|
|
74
|
+
// ============================================================================
|
|
75
|
+
const GenericUserPage = createGenericModulePage();
|
|
76
|
+
const UserPageInner = (props) => {
|
|
77
|
+
const context = useUserModule();
|
|
78
|
+
const userConfig = useMemo(() => createUserConfig({
|
|
79
|
+
dispatch: context.dispatch,
|
|
80
|
+
drawer: context.state.drawer,
|
|
81
|
+
cancelLabel: props.cancelLabel,
|
|
82
|
+
drawerTitle: props.drawerTitle,
|
|
83
|
+
labelActions: props.labelActions,
|
|
84
|
+
labelEmail: props.labelEmail,
|
|
85
|
+
labelEnabled: props.labelEnabled,
|
|
86
|
+
labelId: props.labelId,
|
|
87
|
+
labelName: props.labelName,
|
|
88
|
+
labelPhone: props.labelPhone,
|
|
89
|
+
saveLabel: props.saveLabel,
|
|
90
|
+
searchPlaceholder: props.searchPlaceholder,
|
|
91
|
+
tableDescription: props.tableDescription,
|
|
92
|
+
tableTitle: props.tableTitle,
|
|
93
|
+
}), [
|
|
94
|
+
context.dispatch,
|
|
95
|
+
context.state.drawer,
|
|
96
|
+
props.cancelLabel,
|
|
97
|
+
props.drawerTitle,
|
|
98
|
+
props.labelActions,
|
|
99
|
+
props.labelEmail,
|
|
100
|
+
props.labelEnabled,
|
|
101
|
+
props.labelId,
|
|
102
|
+
props.labelName,
|
|
103
|
+
props.labelPhone,
|
|
104
|
+
props.saveLabel,
|
|
105
|
+
props.searchPlaceholder,
|
|
106
|
+
props.tableDescription,
|
|
107
|
+
props.tableTitle,
|
|
108
|
+
]);
|
|
109
|
+
const hasPermission = resolveRbacPermissions({
|
|
110
|
+
userRole: props.userRole,
|
|
111
|
+
moduleName: "People Management",
|
|
112
|
+
});
|
|
113
|
+
if (!hasPermission) {
|
|
114
|
+
return _jsx(RbacNoAccess, { moduleName: "People Management" });
|
|
115
|
+
}
|
|
116
|
+
return (_jsx("div", { className: "p-4", children: _jsx(GenericUserPage, { overrideConfig: userConfig, context: context, tableBodyCols: tableBodyCols }) }));
|
|
117
|
+
};
|
|
118
|
+
export const UserPage = (props) => {
|
|
119
|
+
return (_jsx(UserProvider, { children: _jsx(UserPageInner, Object.assign({}, props)) }));
|
|
120
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Validation Schema
|
|
3
|
+
*
|
|
4
|
+
* Zod validation schemas for user form data.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { USER_ROLE } from "../../type";
|
|
8
|
+
export declare const userFormValidation: z.ZodObject<{
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
email: z.ZodEmail;
|
|
11
|
+
password: z.ZodOptional<z.ZodString>;
|
|
12
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
13
|
+
avatar: z.ZodOptional<z.ZodString>;
|
|
14
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
userRole: z.ZodEnum<typeof USER_ROLE> & z.ZodType<USER_ROLE.SUPER_ADMIN | USER_ROLE.TEACHER | USER_ROLE.STUDENT | USER_ROLE.PARENT | USER_ROLE.STAFF, USER_ROLE, z.core.$ZodTypeInternals<USER_ROLE.SUPER_ADMIN | USER_ROLE.TEACHER | USER_ROLE.STUDENT | USER_ROLE.PARENT | USER_ROLE.STAFF, USER_ROLE>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Validation Schema
|
|
3
|
+
*
|
|
4
|
+
* Zod validation schemas for user form data.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { USER_ROLE } from "../../type";
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// VALIDATION SCHEMA
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export const userFormValidation = z.object({
|
|
12
|
+
name: z.string().min(1, "Name is required"),
|
|
13
|
+
email: z.email("Invalid email address"),
|
|
14
|
+
password: z.string().optional(),
|
|
15
|
+
phone: z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.refine((val) => !val ||
|
|
19
|
+
/^([+]?[\s0-9]+)?(\d{3}|[(]?[0-9]+[)]?)?([-]?[\s]?[0-9])+$/.test(val), "Invalid phone number format"),
|
|
20
|
+
avatar: z.string().optional(),
|
|
21
|
+
enabled: z.boolean().optional(),
|
|
22
|
+
userRole: z
|
|
23
|
+
.nativeEnum(USER_ROLE, {
|
|
24
|
+
error: "Invalid or missing role",
|
|
25
|
+
})
|
|
26
|
+
.refine((v) => v !== USER_ROLE.SCHOOL_ADMIN, {
|
|
27
|
+
message: "Selecting SCHOOL_ADMIN is not allowed",
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UserView: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useUserModule } from "./context";
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@appcorp/shadcn/components/ui/card";
|
|
5
|
+
import { Badge } from "@appcorp/shadcn/components/ui/badge";
|
|
6
|
+
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
7
|
+
import { Avatar, AvatarFallback, AvatarImage, } from "@appcorp/shadcn/components/ui/avatar";
|
|
8
|
+
import { User, Phone, Mail, CheckCircle2, XCircle } from "lucide-react";
|
|
9
|
+
import { formatValue } from "../../utils/format-value";
|
|
10
|
+
const getInitials = (fullName) => {
|
|
11
|
+
if (!fullName)
|
|
12
|
+
return "U";
|
|
13
|
+
return fullName
|
|
14
|
+
.split(" ")
|
|
15
|
+
.map((n) => n[0] || "")
|
|
16
|
+
.join("")
|
|
17
|
+
.toUpperCase()
|
|
18
|
+
.slice(0, 2);
|
|
19
|
+
};
|
|
20
|
+
export const UserView = () => {
|
|
21
|
+
const { state } = useUserModule();
|
|
22
|
+
const { avatar, email, enabled, name, phone } = state;
|
|
23
|
+
return (_jsx("div", { className: "space-y-4", children: _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(User, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: "User Information" })] }), _jsx(CardDescription, { children: "User account details" })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Profile Picture" }), _jsxs(Avatar, { className: "h-20 w-20", children: [_jsx(AvatarImage, { src: avatar || undefined, alt: name || "User" }), _jsx(AvatarFallback, { className: "text-lg", children: getInitials(name) })] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Name" }), _jsx("p", { className: "text-base", children: formatValue(name) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Mail, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Email Address" })] }), _jsx("p", { className: "text-base", children: formatValue(email) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Phone, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Phone Number" })] }), _jsx("p", { className: "text-base", children: formatValue(phone) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: "Status" }), _jsxs(Badge, { variant: enabled ? "default" : "destructive", className: "gap-1", children: [enabled ? (_jsx(CheckCircle2, { className: "h-3 w-3" })) : (_jsx(XCircle, { className: "h-3 w-3" })), enabled ? "Active" : "Inactive"] })] })] }) })] }) }));
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace User Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for workspace users using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { WorkspaceUserBE } from "../../type";
|
|
7
|
+
export declare const getCachedWorkspaceUsersSync: () => import("@react-pakistan/util-functions").ListResponse<WorkspaceUserBE>;
|
|
8
|
+
export declare const getCachedWorkspaceUsers: ({ params, }: {
|
|
9
|
+
params: Record<string, unknown>;
|
|
10
|
+
}) => Promise<import("@react-pakistan/util-functions").ListResponse<WorkspaceUserBE>>;
|
|
11
|
+
export declare const getCachedWorkspaceUserById: (workspaceUserId: string) => WorkspaceUserBE | null;
|
|
12
|
+
export declare const invalidateWorkspaceUsersCache: () => void;
|
|
13
|
+
export declare const preloadWorkspaceUsers: () => Promise<import("@react-pakistan/util-functions").ListResponse<WorkspaceUserBE>>;
|
|
14
|
+
export declare const isWorkspaceUsersCacheStale: () => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace User Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for workspace users using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { LS_KEYS } from "../../constants";
|
|
7
|
+
import { WORKSPACE_USER_API_ROUTES } from "./constants";
|
|
8
|
+
import { getCachedData, getCachedDataSync, getCachedItemById, invalidateCache, isCacheStale, preloadCache, } from "@react-pakistan/util-functions";
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// CACHE CONFIGURATION
|
|
11
|
+
// ============================================================================
|
|
12
|
+
const WORKSPACE_USER_CACHE_CONFIG = {
|
|
13
|
+
cacheKey: LS_KEYS.WORKSPACE_USERS,
|
|
14
|
+
apiUrl: WORKSPACE_USER_API_ROUTES.UNIT,
|
|
15
|
+
};
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// WORKSPACE_USER-SPECIFIC CACHE FUNCTIONS
|
|
18
|
+
// ============================================================================
|
|
19
|
+
export const getCachedWorkspaceUsersSync = () => getCachedDataSync(LS_KEYS.WORKSPACE_USERS);
|
|
20
|
+
export const getCachedWorkspaceUsers = ({ params, }) => getCachedData({
|
|
21
|
+
config: WORKSPACE_USER_CACHE_CONFIG,
|
|
22
|
+
params,
|
|
23
|
+
headers: {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"x-api-token": process.env.NEXT_PUBLIC_API_KEY,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
export const getCachedWorkspaceUserById = (workspaceUserId) => getCachedItemById(LS_KEYS.WORKSPACE_USERS, workspaceUserId);
|
|
29
|
+
export const invalidateWorkspaceUsersCache = () => invalidateCache(LS_KEYS.WORKSPACE_USERS);
|
|
30
|
+
export const preloadWorkspaceUsers = () => preloadCache(WORKSPACE_USER_CACHE_CONFIG);
|
|
31
|
+
export const isWorkspaceUsersCacheStale = () => isCacheStale(LS_KEYS.WORKSPACE_USERS);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkspaceUser Constants
|
|
3
|
+
*
|
|
4
|
+
* Organization:
|
|
5
|
+
* - Page Configuration
|
|
6
|
+
* - API Routes
|
|
7
|
+
* - Table Configuration
|
|
8
|
+
* - Filter Options
|
|
9
|
+
*/
|
|
10
|
+
export declare const pageLimit: number;
|
|
11
|
+
export declare const WORKSPACE_USER_API_ROUTES: Record<string, string>;
|
|
12
|
+
export declare const ENABLED_OPTIONS: readonly [{
|
|
13
|
+
readonly label: "All";
|
|
14
|
+
readonly value: "";
|
|
15
|
+
}, {
|
|
16
|
+
readonly label: "Enabled";
|
|
17
|
+
readonly value: "true";
|
|
18
|
+
}, {
|
|
19
|
+
readonly label: "Disabled";
|
|
20
|
+
readonly value: "false";
|
|
21
|
+
}];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WorkspaceUser Constants
|
|
3
|
+
*
|
|
4
|
+
* Organization:
|
|
5
|
+
* - Page Configuration
|
|
6
|
+
* - API Routes
|
|
7
|
+
* - Table Configuration
|
|
8
|
+
* - Filter Options
|
|
9
|
+
*/
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// PAGE CONFIGURATION
|
|
12
|
+
// ============================================================================
|
|
13
|
+
export const pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT) || 10;
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// API ROUTES
|
|
16
|
+
// ============================================================================
|
|
17
|
+
export const WORKSPACE_USER_API_ROUTES = {
|
|
18
|
+
UNIT: "/api/v1/workspace-user",
|
|
19
|
+
};
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// ENABLED OPTIONS
|
|
22
|
+
// ============================================================================
|
|
23
|
+
export const ENABLED_OPTIONS = [
|
|
24
|
+
{ label: "All", value: "" },
|
|
25
|
+
{ label: "Enabled", value: "true" },
|
|
26
|
+
{ label: "Disabled", value: "false" },
|
|
27
|
+
];
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { RoleBE, WorkspaceBE, WorkspaceUserBE } from "../../type";
|
|
2
|
+
import { type RowAction } from "@appcorp/shadcn/components/enhanced-table";
|
|
3
|
+
export declare const WORKSPACE_USER_DRAWER: {
|
|
4
|
+
readonly FILTER_DRAWER: string;
|
|
5
|
+
readonly FORM_DRAWER: string;
|
|
6
|
+
readonly MORE_ACTIONS_DRAWER: string;
|
|
7
|
+
readonly VIEW_DRAWER: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const WORKSPACE_USER_ACTION_TYPES: {
|
|
10
|
+
readonly RESET_FORM: "RESET_FORM";
|
|
11
|
+
readonly SET_CURRENT_PAGE: "SET_CURRENT_PAGE";
|
|
12
|
+
readonly SET_PAGE_LIMIT: "SET_PAGE_LIMIT";
|
|
13
|
+
readonly SET_SEARCH_QUERY: "SET_SEARCH_QUERY";
|
|
14
|
+
readonly SET_DRAWER: "SET_DRAWER";
|
|
15
|
+
readonly SET_ITEMS: "SET_ITEMS";
|
|
16
|
+
readonly SET_FORM_DATA: "SET_FORM_DATA";
|
|
17
|
+
readonly SET_DISABLE_SAVE_BUTTON: "SET_DISABLE_SAVE_BUTTON";
|
|
18
|
+
readonly SET_INPUT_FIELD: "SET_INPUT_FIELD";
|
|
19
|
+
readonly SET_ERRORS: "SET_ERRORS";
|
|
20
|
+
readonly SET_FILTERS: "SET_FILTERS";
|
|
21
|
+
}, workspaceUserModuleConfig: import("@react-pakistan/util-functions/factory/generic-module-factory").ModuleConfig<{
|
|
22
|
+
items: WorkspaceUserBE[];
|
|
23
|
+
count: number;
|
|
24
|
+
currentPage: number;
|
|
25
|
+
pageLimit: number;
|
|
26
|
+
searchQuery: string;
|
|
27
|
+
disableSaveButton: boolean;
|
|
28
|
+
drawer: string | null;
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
errors: Record<string, string>;
|
|
31
|
+
filterEnabled: boolean | undefined;
|
|
32
|
+
id: string;
|
|
33
|
+
roleId: string | null;
|
|
34
|
+
userId: string;
|
|
35
|
+
workspaceId: string;
|
|
36
|
+
role: RoleBE | undefined;
|
|
37
|
+
workspace: WorkspaceBE | undefined;
|
|
38
|
+
}>, initialWorkspaceUserState: {
|
|
39
|
+
items: WorkspaceUserBE[];
|
|
40
|
+
count: number;
|
|
41
|
+
currentPage: number;
|
|
42
|
+
pageLimit: number;
|
|
43
|
+
searchQuery: string;
|
|
44
|
+
disableSaveButton: boolean;
|
|
45
|
+
drawer: string | null;
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
errors: Record<string, string>;
|
|
48
|
+
filterEnabled: boolean | undefined;
|
|
49
|
+
id: string;
|
|
50
|
+
roleId: string | null;
|
|
51
|
+
userId: string;
|
|
52
|
+
workspaceId: string;
|
|
53
|
+
role: RoleBE | undefined;
|
|
54
|
+
workspace: WorkspaceBE | undefined;
|
|
55
|
+
}, WorkspaceUserProvider: import("react").FC<{
|
|
56
|
+
children: React.ReactNode;
|
|
57
|
+
}>, workspaceUserReducer: (state: {
|
|
58
|
+
items: WorkspaceUserBE[];
|
|
59
|
+
count: number;
|
|
60
|
+
currentPage: number;
|
|
61
|
+
pageLimit: number;
|
|
62
|
+
searchQuery: string;
|
|
63
|
+
disableSaveButton: boolean;
|
|
64
|
+
drawer: string | null;
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
errors: Record<string, string>;
|
|
67
|
+
filterEnabled: boolean | undefined;
|
|
68
|
+
id: string;
|
|
69
|
+
roleId: string | null;
|
|
70
|
+
userId: string;
|
|
71
|
+
workspaceId: string;
|
|
72
|
+
role: RoleBE | undefined;
|
|
73
|
+
workspace: WorkspaceBE | undefined;
|
|
74
|
+
}, action: any) => {
|
|
75
|
+
items: WorkspaceUserBE[];
|
|
76
|
+
count: number;
|
|
77
|
+
currentPage: number;
|
|
78
|
+
pageLimit: number;
|
|
79
|
+
searchQuery: string;
|
|
80
|
+
disableSaveButton: boolean;
|
|
81
|
+
drawer: string | null;
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
errors: Record<string, string>;
|
|
84
|
+
filterEnabled: boolean | undefined;
|
|
85
|
+
id: string;
|
|
86
|
+
roleId: string | null;
|
|
87
|
+
userId: string;
|
|
88
|
+
workspaceId: string;
|
|
89
|
+
role: RoleBE | undefined;
|
|
90
|
+
workspace: WorkspaceBE | undefined;
|
|
91
|
+
}, useWorkspaceUserContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContext<{
|
|
92
|
+
items: WorkspaceUserBE[];
|
|
93
|
+
count: number;
|
|
94
|
+
currentPage: number;
|
|
95
|
+
pageLimit: number;
|
|
96
|
+
searchQuery: string;
|
|
97
|
+
disableSaveButton: boolean;
|
|
98
|
+
drawer: string | null;
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
errors: Record<string, string>;
|
|
101
|
+
filterEnabled: boolean | undefined;
|
|
102
|
+
id: string;
|
|
103
|
+
roleId: string | null;
|
|
104
|
+
userId: string;
|
|
105
|
+
workspaceId: string;
|
|
106
|
+
role: RoleBE | undefined;
|
|
107
|
+
workspace: WorkspaceBE | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
export declare const useWorkspaceUserModule: () => {
|
|
110
|
+
applyFilters: () => void;
|
|
111
|
+
byIdLoading: boolean;
|
|
112
|
+
clearFilters: () => void;
|
|
113
|
+
deleteLoading: boolean;
|
|
114
|
+
handleChange: (field: string, value: string | number | boolean | undefined | Record<string, string>) => void;
|
|
115
|
+
handleCloseDrawer: () => void;
|
|
116
|
+
handleCreate: () => void;
|
|
117
|
+
handleDelete: (row?: WorkspaceUserBE) => void;
|
|
118
|
+
handleEdit: () => void;
|
|
119
|
+
handleFilters: () => void;
|
|
120
|
+
handleMoreActions: () => void;
|
|
121
|
+
handlePageChange: (page: number) => void;
|
|
122
|
+
handlePageLimitChange: (limit: number) => void;
|
|
123
|
+
handleSearch: (query: string) => void;
|
|
124
|
+
handleSubmit: () => void;
|
|
125
|
+
handleView: () => void;
|
|
126
|
+
headerActions: {
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
handleOnClick: () => void;
|
|
129
|
+
label: string;
|
|
130
|
+
order: number;
|
|
131
|
+
icon: import("react").ForwardRefExoticComponent<Omit<import("lucide-react").LucideProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
132
|
+
}[];
|
|
133
|
+
listLoading: boolean;
|
|
134
|
+
rowActions: RowAction[];
|
|
135
|
+
updateLoading: boolean;
|
|
136
|
+
state: {
|
|
137
|
+
items: WorkspaceUserBE[];
|
|
138
|
+
count: number;
|
|
139
|
+
currentPage: number;
|
|
140
|
+
pageLimit: number;
|
|
141
|
+
searchQuery: string;
|
|
142
|
+
disableSaveButton: boolean;
|
|
143
|
+
drawer: string | null;
|
|
144
|
+
enabled: boolean;
|
|
145
|
+
errors: Record<string, string>;
|
|
146
|
+
filterEnabled: boolean | undefined;
|
|
147
|
+
id: string;
|
|
148
|
+
roleId: string | null;
|
|
149
|
+
userId: string;
|
|
150
|
+
workspaceId: string;
|
|
151
|
+
role: RoleBE | undefined;
|
|
152
|
+
workspace: WorkspaceBE | undefined;
|
|
153
|
+
};
|
|
154
|
+
dispatch: React.Dispatch<any>;
|
|
155
|
+
};
|