@appcorp/fusion-storybook 0.2.56 → 0.2.57
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.
|
@@ -13,31 +13,48 @@ import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
|
13
13
|
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
14
14
|
import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
|
|
15
15
|
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
16
|
-
import { DATE_FORMATS, formatDate } from "@react-pakistan/util-functions";
|
|
16
|
+
import { API_METHODS, DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions";
|
|
17
17
|
import { useEnrollmentModule } from "./context";
|
|
18
|
-
import {
|
|
19
|
-
import { getCachedSectionsSync } from "../section/cache";
|
|
20
|
-
import { SECTION_API_ROUTES, STUDENT_FEE_API_ROUTES, } from "../../constants";
|
|
18
|
+
import { SECTION_API_ROUTES, STUDENT_PROFILE_API_ROUTES, } from "../../constants";
|
|
21
19
|
import { useTranslations } from "next-intl";
|
|
20
|
+
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
21
|
+
import { useEffect } from "storybook/internal/preview-api";
|
|
22
|
+
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
22
23
|
// ============================================================================
|
|
23
24
|
// COMPONENT
|
|
24
25
|
// ============================================================================
|
|
25
26
|
export const EnrollmentForm = () => {
|
|
26
27
|
const { state: { enabled, enrollmentDate, errors, sectionId, studentProfileId }, handleChange, } = useEnrollmentModule();
|
|
28
|
+
const workspace = getCachedWorkspaceSync();
|
|
27
29
|
const t = useTranslations("enrollment");
|
|
30
|
+
const { fetchNow: studentProfileFetchNow, data: studentProfileData } = useFetch(STUDENT_PROFILE_API_ROUTES.UNIT, {
|
|
31
|
+
method: API_METHODS.GET,
|
|
32
|
+
params: { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
|
|
33
|
+
});
|
|
34
|
+
const { fetchNow: sectionFetchNow, data: sectionData } = useFetch(SECTION_API_ROUTES.UNIT, {
|
|
35
|
+
method: API_METHODS.GET,
|
|
36
|
+
params: { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
|
|
37
|
+
});
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (workspace === null || workspace === void 0 ? void 0 : workspace.id) {
|
|
40
|
+
studentProfileFetchNow();
|
|
41
|
+
sectionFetchNow();
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
+
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
28
45
|
const { enhancedComboboxElement: studentProfileIdCombo } = useEnhancedCombobox({
|
|
29
46
|
emptyText: t("formNoStudentEmpty"),
|
|
30
47
|
id: "studentProfileId",
|
|
31
48
|
info: t("formStudentInfo"),
|
|
32
49
|
label: t("formStudentLabel"),
|
|
33
50
|
onValueChange: (value) => handleChange("studentProfileId", value),
|
|
34
|
-
options: (
|
|
51
|
+
options: ((studentProfileData === null || studentProfileData === void 0 ? void 0 : studentProfileData.items) || []).map((s) => ({
|
|
35
52
|
value: s.id,
|
|
36
|
-
label: s.studentCode
|
|
53
|
+
label: s.studentCode,
|
|
37
54
|
})),
|
|
38
55
|
placeholder: t("formStudentPlaceholder"),
|
|
39
56
|
required: true,
|
|
40
|
-
searchEndpoint:
|
|
57
|
+
searchEndpoint: STUDENT_PROFILE_API_ROUTES.UNIT,
|
|
41
58
|
searchPlaceholder: t("formSearchStudentsPlaceholder"),
|
|
42
59
|
formatSearchResult: (item) => {
|
|
43
60
|
var _a, _b;
|
|
@@ -54,7 +71,7 @@ export const EnrollmentForm = () => {
|
|
|
54
71
|
info: t("sectionInfo"),
|
|
55
72
|
label: t("section"),
|
|
56
73
|
onValueChange: (value) => handleChange("sectionId", value),
|
|
57
|
-
options: (
|
|
74
|
+
options: ((sectionData === null || sectionData === void 0 ? void 0 : sectionData.items) || []).map((s) => {
|
|
58
75
|
var _a;
|
|
59
76
|
return ({
|
|
60
77
|
value: s.id,
|