@appcorp/fusion-storybook 0.2.63 → 0.2.64
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/course/context.d.ts +12 -0
- package/base-modules/course/context.js +23 -7
- package/base-modules/course/form.js +34 -3
- package/base-modules/course/page.d.ts +1 -0
- package/base-modules/course/page.js +16 -5
- package/base-modules/course/validate.d.ts +1 -0
- package/base-modules/course/validate.js +1 -0
- package/base-modules/course/view.js +6 -2
- package/base-modules/enrollment/context.d.ts +13 -1
- package/base-modules/enrollment/context.js +3 -0
- package/base-modules/enrollment/form.js +31 -3
- package/base-modules/enrollment/more-actions.js +9 -7
- package/base-modules/enrollment/page.d.ts +1 -0
- package/base-modules/enrollment/page.js +15 -4
- package/base-modules/enrollment/validate.d.ts +1 -0
- package/base-modules/enrollment/validate.js +1 -0
- package/base-modules/enrollment/view.js +5 -2
- package/base-modules/section/cache.js +0 -1
- package/base-modules/section/context.d.ts +0 -6
- package/base-modules/section/context.js +0 -3
- package/base-modules/section/form.js +2 -41
- package/base-modules/section/more-actions.js +5 -7
- package/base-modules/section/page.d.ts +0 -1
- package/base-modules/section/page.js +3 -7
- package/base-modules/section/validate.d.ts +0 -1
- package/base-modules/section/validate.js +0 -1
- package/base-modules/section/view.js +2 -10
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/academics.d.ts +5 -2
|
@@ -8,6 +8,7 @@ import { z } from "zod";
|
|
|
8
8
|
// VALIDATION SCHEMA
|
|
9
9
|
// ============================================================================
|
|
10
10
|
export const enrollmentFormValidation = z.object({
|
|
11
|
+
classId: z.string().min(1, "Class is required"),
|
|
11
12
|
studentProfileId: z.string().min(1, "Student is required"),
|
|
12
13
|
sectionId: z.string().min(1, "Section is required"),
|
|
13
14
|
enrollmentDate: z
|
|
@@ -16,6 +16,7 @@ import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
|
16
16
|
import { BookOpen, CheckCircle2, XCircle } from "lucide-react";
|
|
17
17
|
import { DATE_FORMATS, formatDate } from "@react-pakistan/util-functions";
|
|
18
18
|
import { useEnrollmentModule } from "./context";
|
|
19
|
+
import { getCachedClassesSync } from "../class/cache";
|
|
19
20
|
import { getCachedStudentProfilesSync } from "../student-profile/cache";
|
|
20
21
|
import { getCachedSectionsSync } from "../section/cache";
|
|
21
22
|
import { useTranslations } from "next-intl";
|
|
@@ -24,17 +25,19 @@ import { useTranslations } from "next-intl";
|
|
|
24
25
|
// ============================================================================
|
|
25
26
|
export const EnrollmentView = memo(() => {
|
|
26
27
|
var _a, _b, _c;
|
|
27
|
-
const { state: { enrollmentDate, enabled, sectionId, studentProfileId }, } = useEnrollmentModule();
|
|
28
|
+
const { state: { classId, enrollmentDate, enabled, sectionId, studentProfileId }, } = useEnrollmentModule();
|
|
28
29
|
const t = useTranslations("enrollment");
|
|
29
30
|
const studentProfile = getCachedStudentProfilesSync().items.find((s) => s.id === studentProfileId);
|
|
30
31
|
const studentName = (_b = (_a = studentProfile === null || studentProfile === void 0 ? void 0 : studentProfile.studentCode) !== null && _a !== void 0 ? _a : studentProfileId) !== null && _b !== void 0 ? _b : "—";
|
|
32
|
+
const cls = getCachedClassesSync().items.find((c) => c.id === classId);
|
|
33
|
+
const className = cls ? `${cls.name} (${cls.code})` : (classId !== null && classId !== void 0 ? classId : "—");
|
|
31
34
|
const section = getCachedSectionsSync().items.find((s) => s.id === sectionId);
|
|
32
35
|
const sectionName = section
|
|
33
36
|
? ((_c = section.class) === null || _c === void 0 ? void 0 : _c.code)
|
|
34
37
|
? `${section.class.code}-${section.name}`
|
|
35
38
|
: section.name
|
|
36
39
|
: (sectionId !== null && sectionId !== void 0 ? sectionId : "—");
|
|
37
|
-
return (_jsxs("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(BookOpen, { className: "h-5 w-5 text-primary" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionEnrollmentDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteEnrollmentInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("viewFieldStudent") }), _jsx("p", { className: "text-base", children: studentName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("section") }), _jsx("p", { className: "text-base", children: sectionName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("viewFieldEnrollmentDate") }), _jsx("p", { className: "text-base", children: enrollmentDate
|
|
40
|
+
return (_jsxs("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(BookOpen, { className: "h-5 w-5 text-primary" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionEnrollmentDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteEnrollmentInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("viewFieldStudent") }), _jsx("p", { className: "text-base", children: studentName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("labelClass") }), _jsx("p", { className: "text-base", children: className })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("section") }), _jsx("p", { className: "text-base", children: sectionName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("viewFieldEnrollmentDate") }), _jsx("p", { className: "text-base", children: enrollmentDate
|
|
38
41
|
? formatDate(enrollmentDate, DATE_FORMATS.LOCALE_DATE)
|
|
39
42
|
: "—" })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "h-5 w-5 text-primary" }), _jsx(CardTitle, { className: "text-lg", children: t("viewFieldStatus") })] }), _jsx(CardDescription, { children: t("viewFieldEnrollmentAvailability") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsx("div", { className: "grid grid-cols-1 gap-6", children: _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "destructive", className: "gap-1", children: enabled ? (_jsxs(_Fragment, { children: [_jsx(CheckCircle2, { className: "h-3 w-3" }), " ", t("viewFieldStatusActive")] })) : (_jsxs(_Fragment, { children: [_jsx(XCircle, { className: "h-3 w-3" }), " ", t("viewFieldStatusInactive")] })) })] }) }) })] })] }));
|
|
40
43
|
});
|
|
@@ -21,7 +21,6 @@ export const getCachedSections = ({ params, }) => getCachedData({
|
|
|
21
21
|
params,
|
|
22
22
|
headers: {
|
|
23
23
|
"Content-Type": "application/json",
|
|
24
|
-
// "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
|
|
25
24
|
},
|
|
26
25
|
});
|
|
27
26
|
export const getCachedSectionById = (sectionId) => getCachedItemById(LS_KEYS.SECTIONS, sectionId);
|
|
@@ -28,7 +28,6 @@ export declare const SECTION_ACTION_TYPES: {
|
|
|
28
28
|
drawer: string | null;
|
|
29
29
|
errors: Record<string, string>;
|
|
30
30
|
capacity: number | null;
|
|
31
|
-
classId: string;
|
|
32
31
|
enabled: boolean;
|
|
33
32
|
id: string;
|
|
34
33
|
name: string;
|
|
@@ -44,7 +43,6 @@ export declare const SECTION_ACTION_TYPES: {
|
|
|
44
43
|
drawer: string | null;
|
|
45
44
|
errors: Record<string, string>;
|
|
46
45
|
capacity: number | null;
|
|
47
|
-
classId: string;
|
|
48
46
|
enabled: boolean;
|
|
49
47
|
id: string;
|
|
50
48
|
name: string;
|
|
@@ -62,7 +60,6 @@ export declare const SECTION_ACTION_TYPES: {
|
|
|
62
60
|
drawer: string | null;
|
|
63
61
|
errors: Record<string, string>;
|
|
64
62
|
capacity: number | null;
|
|
65
|
-
classId: string;
|
|
66
63
|
enabled: boolean;
|
|
67
64
|
id: string;
|
|
68
65
|
name: string;
|
|
@@ -78,7 +75,6 @@ export declare const SECTION_ACTION_TYPES: {
|
|
|
78
75
|
drawer: string | null;
|
|
79
76
|
errors: Record<string, string>;
|
|
80
77
|
capacity: number | null;
|
|
81
|
-
classId: string;
|
|
82
78
|
enabled: boolean;
|
|
83
79
|
id: string;
|
|
84
80
|
name: string;
|
|
@@ -94,7 +90,6 @@ export declare const SECTION_ACTION_TYPES: {
|
|
|
94
90
|
drawer: string | null;
|
|
95
91
|
errors: Record<string, string>;
|
|
96
92
|
capacity: number | null;
|
|
97
|
-
classId: string;
|
|
98
93
|
enabled: boolean;
|
|
99
94
|
id: string;
|
|
100
95
|
name: string;
|
|
@@ -143,7 +138,6 @@ export declare const useSectionModule: () => {
|
|
|
143
138
|
drawer: string | null;
|
|
144
139
|
errors: Record<string, string>;
|
|
145
140
|
capacity: number | null;
|
|
146
|
-
classId: string;
|
|
147
141
|
enabled: boolean;
|
|
148
142
|
id: string;
|
|
149
143
|
name: string;
|
|
@@ -57,7 +57,6 @@ const sectionConfig = {
|
|
|
57
57
|
errors: {},
|
|
58
58
|
// Form State
|
|
59
59
|
capacity: null,
|
|
60
|
-
classId: "",
|
|
61
60
|
enabled: true,
|
|
62
61
|
id: "",
|
|
63
62
|
name: "",
|
|
@@ -101,7 +100,6 @@ export const useSectionModule = () => {
|
|
|
101
100
|
]);
|
|
102
101
|
const updateParams = useMemo(() => ({
|
|
103
102
|
capacity: state.capacity,
|
|
104
|
-
classId: state.classId,
|
|
105
103
|
enabled: state.enabled,
|
|
106
104
|
id: state.id,
|
|
107
105
|
name: state.name,
|
|
@@ -150,7 +148,6 @@ export const useSectionModule = () => {
|
|
|
150
148
|
payload: {
|
|
151
149
|
form: {
|
|
152
150
|
capacity: null,
|
|
153
|
-
classId: "",
|
|
154
151
|
enabled: true,
|
|
155
152
|
filterEnabled: undefined,
|
|
156
153
|
id: "",
|
|
@@ -7,53 +7,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* Uses a class combobox populated from cached class data.
|
|
8
8
|
*/
|
|
9
9
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
10
|
-
import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
|
|
11
10
|
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
12
11
|
import { useSectionModule } from "./context";
|
|
13
12
|
import { useTranslations } from "next-intl";
|
|
14
|
-
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
15
|
-
import { CLASS_API_ROUTES } from "../../constants";
|
|
16
|
-
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
17
|
-
import { API_METHODS } from "@react-pakistan/util-functions";
|
|
18
|
-
import { useEffect } from "react";
|
|
19
13
|
export const SectionForm = () => {
|
|
20
|
-
var _a;
|
|
21
14
|
const { state, handleChange } = useSectionModule();
|
|
22
|
-
const { capacity,
|
|
15
|
+
const { capacity, enabled, errors, name } = state;
|
|
23
16
|
const t = useTranslations("section");
|
|
24
|
-
|
|
25
|
-
const { fetchNow, data: classes } = useFetch(CLASS_API_ROUTES.UNIT, {
|
|
26
|
-
params: { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
|
|
27
|
-
method: API_METHODS.GET,
|
|
28
|
-
});
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
fetchNow();
|
|
31
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
-
}, []);
|
|
33
|
-
const { enhancedComboboxElement: classIdCombo } = useEnhancedCombobox({
|
|
34
|
-
emptyText: t("formNoClassEmpty"),
|
|
35
|
-
id: "classId",
|
|
36
|
-
info: t("formClassInfo"),
|
|
37
|
-
label: t("formClassLabel"),
|
|
38
|
-
onValueChange: (value) => handleChange("classId", value),
|
|
39
|
-
options: ((_a = ((classes === null || classes === void 0 ? void 0 : classes.items) || [])) === null || _a === void 0 ? void 0 : _a.map((cls) => ({
|
|
40
|
-
value: cls.id,
|
|
41
|
-
label: `${cls.name} (${cls.code})`,
|
|
42
|
-
}))) || [],
|
|
43
|
-
placeholder: t("formClassPlaceholder"),
|
|
44
|
-
required: true,
|
|
45
|
-
searchEndpoint: CLASS_API_ROUTES.UNIT,
|
|
46
|
-
searchPlaceholder: t("formSearchClassesPlaceholder"),
|
|
47
|
-
formatSearchResult: (item) => {
|
|
48
|
-
const classItem = Object.assign({}, item);
|
|
49
|
-
return {
|
|
50
|
-
label: `${classItem === null || classItem === void 0 ? void 0 : classItem.name} (${classItem === null || classItem === void 0 ? void 0 : classItem.code})`,
|
|
51
|
-
value: classItem === null || classItem === void 0 ? void 0 : classItem.id,
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
value: classId,
|
|
55
|
-
});
|
|
56
|
-
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [classIdCombo, _jsx(EnhancedInput, { error: errors.name, id: "name", info: t("sectionNameInfo"), label: t("sectionName"), onChange: (e) => handleChange("name", e.target.value), placeholder: t("sectionNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: errors.capacity, id: "capacity", info: t("formCapacityInfo"), label: t("formCapacityLabel"), onChange: (e) => {
|
|
17
|
+
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: errors.name, id: "name", info: t("sectionNameInfo"), label: t("sectionName"), onChange: (e) => handleChange("name", e.target.value), placeholder: t("sectionNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: errors.capacity, id: "capacity", info: t("formCapacityInfo"), label: t("formCapacityLabel"), onChange: (e) => {
|
|
57
18
|
const value = e.target.value;
|
|
58
19
|
handleChange("capacity", value ? Number(value) : 0);
|
|
59
20
|
}, placeholder: t("formCapacityPlaceholder"), type: "number", value: (capacity === null || capacity === void 0 ? void 0 : capacity.toString()) || "" }), _jsx(EnhancedCheckbox, { label: t("formActiveSectionLabel"), defaultChecked: enabled, onCheckedChange: (checked) => handleChange("enabled", checked), info: t("actionToggleActivateOrDeactivateSection") })] }));
|
|
@@ -91,7 +91,7 @@ export const SectionMoreActions = () => {
|
|
|
91
91
|
};
|
|
92
92
|
}, []);
|
|
93
93
|
const handleBulkFlow = useCallback(async (files, method) => {
|
|
94
|
-
var _a, _b, _c, _d, _e, _f
|
|
94
|
+
var _a, _b, _c, _d, _e, _f;
|
|
95
95
|
const closeDrawer = () => {
|
|
96
96
|
dispatch({
|
|
97
97
|
type: SECTION_ACTION_TYPES.SET_DRAWER,
|
|
@@ -120,11 +120,9 @@ export const SectionMoreActions = () => {
|
|
|
120
120
|
if (method === "POST") {
|
|
121
121
|
if (!((_b = row.name) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
122
122
|
msgs.push(t("validationRequiredName"));
|
|
123
|
-
if (!((_c = row.classId) === null || _c === void 0 ? void 0 : _c.trim()))
|
|
124
|
-
msgs.push(t("validationRequiredClassId"));
|
|
125
123
|
}
|
|
126
124
|
else {
|
|
127
|
-
if (!((
|
|
125
|
+
if (!((_c = row.id) === null || _c === void 0 ? void 0 : _c.trim()))
|
|
128
126
|
msgs.push(t("validationRequiredIdForUpdate"));
|
|
129
127
|
}
|
|
130
128
|
if (msgs.length > 0) {
|
|
@@ -167,7 +165,7 @@ export const SectionMoreActions = () => {
|
|
|
167
165
|
return;
|
|
168
166
|
if (status.status === "completed") {
|
|
169
167
|
const r = status.results;
|
|
170
|
-
if (r && ((
|
|
168
|
+
if (r && ((_d = r.errors) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
171
169
|
const summary = formatErrorSummary(t, r.errors);
|
|
172
170
|
showSuccessToast(t("messagesBulkResults", {
|
|
173
171
|
created: r.created,
|
|
@@ -187,7 +185,7 @@ export const SectionMoreActions = () => {
|
|
|
187
185
|
else {
|
|
188
186
|
showSuccessToast(t("messagesBulkSuccess"));
|
|
189
187
|
}
|
|
190
|
-
const schoolId = ((
|
|
188
|
+
const schoolId = ((_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.id) || "";
|
|
191
189
|
fetch(`${SECTION_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
192
190
|
headers: {
|
|
193
191
|
"Content-Type": "application/json",
|
|
@@ -211,7 +209,7 @@ export const SectionMoreActions = () => {
|
|
|
211
209
|
}
|
|
212
210
|
else {
|
|
213
211
|
const r = status.results;
|
|
214
|
-
const detail = ((
|
|
212
|
+
const detail = ((_f = r === null || r === void 0 ? void 0 : r.errors) === null || _f === void 0 ? void 0 : _f.length)
|
|
215
213
|
? formatErrorSummary(t, r.errors)
|
|
216
214
|
: t("unknownError");
|
|
217
215
|
showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
|
|
@@ -33,7 +33,6 @@ import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
|
33
33
|
const tableBodyCols = [
|
|
34
34
|
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
35
35
|
{ componentType: COMPONENT_TYPE.BOLD_TEXT, key: "name" },
|
|
36
|
-
{ componentType: COMPONENT_TYPE.OBJECT, key: ["class:name"] },
|
|
37
36
|
{ componentType: COMPONENT_TYPE.TEXT, key: "capacity" },
|
|
38
37
|
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
|
|
39
38
|
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
@@ -47,15 +46,14 @@ const createComponentInstances = () => ({
|
|
|
47
46
|
moreActions: _jsx(SectionMoreActions, {}),
|
|
48
47
|
view: _jsx(SectionView, {}),
|
|
49
48
|
});
|
|
50
|
-
const createSectionConfig = ({ cancelLabel, dispatch, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, labelActions, labelCapacity,
|
|
49
|
+
const createSectionConfig = ({ cancelLabel, dispatch, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, labelActions, labelCapacity, labelEnabled, labelId, labelName, saveLabel, searchPlaceholder, tableDescription, tableTitle, }) => {
|
|
51
50
|
const components = createComponentInstances();
|
|
52
51
|
return {
|
|
53
52
|
moduleName: "section",
|
|
54
53
|
tableColumns: [
|
|
55
54
|
{ label: labelId, width: "5%" },
|
|
56
|
-
{ label: labelName, width: "
|
|
57
|
-
{ label:
|
|
58
|
-
{ label: labelCapacity, width: "20%" },
|
|
55
|
+
{ label: labelName, width: "30%" },
|
|
56
|
+
{ label: labelCapacity, width: "25%" },
|
|
59
57
|
{ label: labelEnabled, width: "15%" },
|
|
60
58
|
{ label: labelActions, width: "5%" },
|
|
61
59
|
],
|
|
@@ -100,7 +98,6 @@ const SectionPageInner = (props) => {
|
|
|
100
98
|
drawerMoreActionsDescription: props.drawerMoreActionsDescription,
|
|
101
99
|
labelActions: props.labelActions,
|
|
102
100
|
labelCapacity: props.labelCapacity,
|
|
103
|
-
labelClass: props.labelClass,
|
|
104
101
|
labelEnabled: props.labelEnabled,
|
|
105
102
|
labelId: props.labelId,
|
|
106
103
|
labelName: props.labelName,
|
|
@@ -121,7 +118,6 @@ const SectionPageInner = (props) => {
|
|
|
121
118
|
props.drawerMoreActionsDescription,
|
|
122
119
|
props.labelActions,
|
|
123
120
|
props.labelCapacity,
|
|
124
|
-
props.labelClass,
|
|
125
121
|
props.labelEnabled,
|
|
126
122
|
props.labelId,
|
|
127
123
|
props.labelName,
|
|
@@ -13,7 +13,6 @@ export const sectionFormValidation = z.object({
|
|
|
13
13
|
.min(1, "Name is required")
|
|
14
14
|
.max(100, "Name must be less than 100 characters")
|
|
15
15
|
.regex(/^[a-zA-Z0-9\s\-_]+$/, "Name can only contain letters, numbers, spaces, hyphens, and underscores"),
|
|
16
|
-
classId: z.string().min(1, "Class is required"),
|
|
17
16
|
capacity: z
|
|
18
17
|
.number()
|
|
19
18
|
.int()
|
|
@@ -12,19 +12,11 @@ import { GraduationCap, CheckCircle2, XCircle, Users } from "lucide-react";
|
|
|
12
12
|
import { useSectionModule } from "./context";
|
|
13
13
|
import { useTranslations } from "next-intl";
|
|
14
14
|
import { formatValue } from "@react-pakistan/util-functions/general/format-value";
|
|
15
|
-
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
16
|
-
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
17
|
-
import { API_METHODS } from "@react-pakistan/util-functions";
|
|
18
15
|
export const SectionView = () => {
|
|
19
16
|
const { state } = useSectionModule();
|
|
20
|
-
const { capacity,
|
|
21
|
-
const workspace = getCachedWorkspaceSync();
|
|
17
|
+
const { capacity, enabled, name } = state;
|
|
22
18
|
const t = useTranslations("section");
|
|
23
|
-
|
|
24
|
-
params: { classId, workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
|
|
25
|
-
method: API_METHODS.GET,
|
|
26
|
-
});
|
|
27
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Card, { children: _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "flex items-center gap-6", children: [_jsx("div", { className: "bg-primary/10 flex h-24 w-24 items-center justify-center rounded-full", children: _jsx(Users, { className: "text-primary h-12 w-12" }) }), _jsxs("div", { className: "flex-1", children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("h2", { className: "text-2xl font-bold", children: name }), enabled ? (_jsx(CheckCircle2, { className: "h-5 w-5 text-green-500" })) : (_jsx(XCircle, { className: "h-5 w-5 text-red-500" }))] }), _jsxs("p", { className: "text-muted-foreground mt-1", children: [t("viewFieldClass"), ": ", (classData === null || classData === void 0 ? void 0 : classData.name) || "—"] })] })] }) }) }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(GraduationCap, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("sectionDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteSectionInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("sectionName") }), _jsx("p", { className: "text-base", children: formatValue(name) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldClass") }), _jsx("p", { className: "text-base", children: (classData === null || classData === void 0 ? void 0 : classData.name) || "—" })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldCapacity") }), _jsxs("p", { className: "text-base", children: [formatValue(capacity), " ", capacity !== null ? t("viewFieldStudents") : ""] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "secondary", children: enabled
|
|
19
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Card, { children: _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "flex items-center gap-6", children: [_jsx("div", { className: "bg-primary/10 flex h-24 w-24 items-center justify-center rounded-full", children: _jsx(Users, { className: "text-primary h-12 w-12" }) }), _jsx("div", { className: "flex-1", children: _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("h2", { className: "text-2xl font-bold", children: name }), enabled ? (_jsx(CheckCircle2, { className: "h-5 w-5 text-green-500" })) : (_jsx(XCircle, { className: "h-5 w-5 text-red-500" }))] }) })] }) }) }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(GraduationCap, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("sectionDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteSectionInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("sectionName") }), _jsx("p", { className: "text-base", children: formatValue(name) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldCapacity") }), _jsxs("p", { className: "text-base", children: [formatValue(capacity), " ", capacity !== null ? t("viewFieldStudents") : ""] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "secondary", children: enabled
|
|
28
20
|
? t("viewFieldStatusActive")
|
|
29
21
|
: t("viewFieldStatusInactive") })] })] }) })] })] }));
|
|
30
22
|
};
|