@appcorp/fusion-storybook 0.4.16 → 0.4.17
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.
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface BuildAutoPostPayloadInput {
|
|
2
|
+
schoolId: string;
|
|
3
|
+
computerNumbers: string[];
|
|
4
|
+
paidAt: string;
|
|
5
|
+
skipFine: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildAutoPostPayload(input: BuildAutoPostPayloadInput): {
|
|
8
|
+
skipFine?: boolean | undefined;
|
|
9
|
+
schoolId: string;
|
|
10
|
+
computerNumbers: string[];
|
|
11
|
+
paidAt: string;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -22,6 +22,12 @@ import { DISCOUNT_TYPE, PAYMENT_STATUS } from "../../types";
|
|
|
22
22
|
import { PAYMENT_STATUS_OPTIONS } from "./constants";
|
|
23
23
|
import { Loader2 } from "lucide-react";
|
|
24
24
|
import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
|
|
25
|
+
function toLocalDateString(date) {
|
|
26
|
+
const year = date.getFullYear();
|
|
27
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
28
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
29
|
+
return `${year}-${month}-${day}`;
|
|
30
|
+
}
|
|
25
31
|
export const StudentFeeSingle = () => {
|
|
26
32
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
27
33
|
const { dispatch, handleChange, state } = useStudentFeeModule();
|
|
@@ -40,13 +46,14 @@ export const StudentFeeSingle = () => {
|
|
|
40
46
|
var _a;
|
|
41
47
|
if (!debouncedComputerNumber)
|
|
42
48
|
return;
|
|
49
|
+
// When the chosen payment date differs from today, ask the API to recompute
|
|
50
|
+
// the fines as of that back-dated (or future) payment date.
|
|
51
|
+
const today = toLocalDateString(new Date());
|
|
52
|
+
const useAsOf = state.paidAt && state.paidAt !== today;
|
|
43
53
|
fetchByCNRef.current(undefined, {
|
|
44
|
-
params: {
|
|
45
|
-
computerNumber: debouncedComputerNumber,
|
|
46
|
-
schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
47
|
-
},
|
|
54
|
+
params: Object.assign({ computerNumber: debouncedComputerNumber, schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id }, (useAsOf ? { asOf: state.paidAt } : {})),
|
|
48
55
|
});
|
|
49
|
-
}, [debouncedComputerNumber, (_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id]);
|
|
56
|
+
}, [debouncedComputerNumber, (_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id, state.paidAt]);
|
|
50
57
|
const accumulatedAmount = useMemo(() => {
|
|
51
58
|
var _a;
|
|
52
59
|
if (!((_a = feeByComputerNumber === null || feeByComputerNumber === void 0 ? void 0 : feeByComputerNumber.studentFees) === null || _a === void 0 ? void 0 : _a.length))
|
|
@@ -4,12 +4,14 @@ import { showErrorToast, showSuccessToast, showInfoToast, } from "@appcorp/shadc
|
|
|
4
4
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
5
5
|
import { useTranslations } from "next-intl";
|
|
6
6
|
import { STUDENT_FEE_API_ROUTES } from "../../constants";
|
|
7
|
+
import { buildAutoPostPayload } from "./auto-post-payload";
|
|
7
8
|
import { STUDENT_FEE_ACTION_TYPES, useStudentFeeModule } from "./context";
|
|
8
9
|
import { useRef, useEffect, useCallback, useState } from "react";
|
|
9
10
|
import { Button } from "@appcorp/shadcn/components/ui/button";
|
|
10
11
|
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
11
12
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
12
13
|
import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
|
|
14
|
+
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
13
15
|
const workspace = getCachedWorkspaceSync();
|
|
14
16
|
const POLL_INTERVAL_MS = 2000;
|
|
15
17
|
const POLL_TIMEOUT_MS = 300000;
|
|
@@ -61,6 +63,7 @@ export const StudentFeeMoreActions = () => {
|
|
|
61
63
|
const abortRef = useRef(null);
|
|
62
64
|
const [autoPostDate, setAutoPostDate] = useState("");
|
|
63
65
|
const [computerNumbersText, setComputerNumbersText] = useState("");
|
|
66
|
+
const [skipFine, setSkipFine] = useState(false);
|
|
64
67
|
const [submitting, setSubmitting] = useState(false);
|
|
65
68
|
useEffect(() => {
|
|
66
69
|
return () => {
|
|
@@ -127,11 +130,12 @@ export const StudentFeeMoreActions = () => {
|
|
|
127
130
|
headers: {
|
|
128
131
|
"Content-Type": "application/json",
|
|
129
132
|
},
|
|
130
|
-
body: JSON.stringify({
|
|
133
|
+
body: JSON.stringify(buildAutoPostPayload({
|
|
131
134
|
schoolId,
|
|
132
135
|
computerNumbers: uniqueNumbers,
|
|
133
136
|
paidAt: autoPostDate,
|
|
134
|
-
|
|
137
|
+
skipFine,
|
|
138
|
+
})),
|
|
135
139
|
signal,
|
|
136
140
|
});
|
|
137
141
|
if (!res.ok) {
|
|
@@ -187,9 +191,9 @@ export const StudentFeeMoreActions = () => {
|
|
|
187
191
|
finally {
|
|
188
192
|
setSubmitting(false);
|
|
189
193
|
}
|
|
190
|
-
}, [t, dispatch, closeDrawer, refreshList, computerNumbersText, autoPostDate]);
|
|
194
|
+
}, [t, dispatch, closeDrawer, refreshList, computerNumbersText, autoPostDate, skipFine]);
|
|
191
195
|
const canSubmit = autoPostDate.trim() !== "" &&
|
|
192
196
|
computerNumbersText.trim() !== "" &&
|
|
193
197
|
!submitting;
|
|
194
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Button, { disabled: new Date().getDate() !== 1, onClick: handleCreateMonthly, children: t("actionsButtonCreateMonthly") }), _jsx(Button, { onClick: handleCreateSingleEntry, children: t("actionsButtonSingleEntry") }), _jsx(Separator, {}), _jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { id: "autoPostDate", info: t("formAutoPostDateInfo"), label: t("formAutoPostDateLabel"), onChange: (e) => setAutoPostDate(e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: autoPostDate }), _jsx(EnhancedTextarea, { id: "autoPostComputerNumbers", info: t("formAutoPostComputerNumbersInfo"), label: t("formAutoPostComputerNumbersLabel"), onChange: (e) => setComputerNumbersText(e.target.value), placeholder: t("formAutoPostComputerNumbersPlaceholder"), rows: 8, value: computerNumbersText }), _jsx(Button, { disabled: !canSubmit, onClick: handleAutoPost, children: t("actionsButtonAutoPost") })] })] }));
|
|
198
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(Button, { disabled: new Date().getDate() !== 1, onClick: handleCreateMonthly, children: t("actionsButtonCreateMonthly") }), _jsx(Button, { onClick: handleCreateSingleEntry, children: t("actionsButtonSingleEntry") }), _jsx(Separator, {}), _jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { id: "autoPostDate", info: t("formAutoPostDateInfo"), label: t("formAutoPostDateLabel"), onChange: (e) => setAutoPostDate(e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: autoPostDate }), _jsx(EnhancedTextarea, { id: "autoPostComputerNumbers", info: t("formAutoPostComputerNumbersInfo"), label: t("formAutoPostComputerNumbersLabel"), onChange: (e) => setComputerNumbersText(e.target.value), placeholder: t("formAutoPostComputerNumbersPlaceholder"), rows: 8, value: computerNumbersText }), _jsx(EnhancedCheckbox, { id: "autoPostSkipFine", checked: skipFine, info: t("formSkipFineInfo"), label: t("formSkipFineLabel"), onCheckedChange: (checked) => setSkipFine(!!checked) }), _jsx(Button, { disabled: !canSubmit, onClick: handleAutoPost, children: t("actionsButtonAutoPost") })] })] }));
|
|
195
199
|
};
|