added payment history, setting pages
This commit is contained in:
1 parent
1c0cbf1023
commit
1ebc133d1c
35 files changed
+1626
-1273
No files matched your search
@@ -9,23 +9,29 @@ import { FormActions } from "@/components/formActions";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import type { VisaMasterSetting } from "../api/visaMasterSberSettingsApi";
|
||||
import { useCreateVisaMasterSetting, useUpdateVisaMasterSetting } from "../hooks/useVisaMasterSettings";
|
||||
import { createVisaMasterSettingFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/visaMasterSberSetting.schema";
|
||||
import {
|
||||
createVisaMasterSettingFormSchema,
|
||||
DEFAULT_FORM_VALUES,
|
||||
buildCreatePayload,
|
||||
buildUpdatePayload,
|
||||
} from "../schemas/visaMasterSberSetting.schema";
|
||||
import type { VisaMasterSettingFormData } from "../schemas/visaMasterSberSetting.schema";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
const LIST_PATH = "/visa-master-sber-settings";
|
||||
|
||||
export interface VisaMasterSettingFormProps {
|
||||
mode: "create" | "edit";
|
||||
initialData?: VisaMasterSetting;
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function mapInitial(data: VisaMasterSetting): VisaMasterSettingFormData {
|
||||
return {
|
||||
kod: data.kod,
|
||||
ady: data.ady,
|
||||
yazgy: data.yazgy,
|
||||
code: data.code,
|
||||
name: data.name,
|
||||
isActive: data.isActive,
|
||||
textTm: data.text?.tm ?? "",
|
||||
textRu: data.text?.ru ?? "",
|
||||
textEn: data.text?.en ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,8 +46,6 @@ function flattenErrors(errors: Record<string, { message?: string } | undefined>)
|
||||
return result;
|
||||
}
|
||||
|
||||
// ─── VisaMasterSettingForm ────────────────────────────────────────────────────
|
||||
|
||||
export function VisaMasterSettingForm({ mode, initialData }: VisaMasterSettingFormProps) {
|
||||
const { t: _t, i18n } = useTranslation();
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
@@ -53,8 +57,7 @@ export function VisaMasterSettingForm({ mode, initialData }: VisaMasterSettingFo
|
||||
const navigate = useNavigate();
|
||||
|
||||
const createMutation = useCreateVisaMasterSetting();
|
||||
const updateMutation = useUpdateVisaMasterSetting(initialData?.id ?? 0);
|
||||
|
||||
const updateMutation = useUpdateVisaMasterSetting(initialData?.code ?? "");
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const schema = useMemo(
|
||||
@@ -79,14 +82,12 @@ export function VisaMasterSettingForm({ mode, initialData }: VisaMasterSettingFo
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors]);
|
||||
|
||||
useEffect(() => {
|
||||
if (Object.keys(rhfErrors).length > 0) {
|
||||
trigger();
|
||||
}
|
||||
if (Object.keys(rhfErrors).length > 0) trigger();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [i18n.language]);
|
||||
|
||||
const set = useCallback(
|
||||
(key: keyof VisaMasterSettingFormData) => (value: string) => {
|
||||
(key: Exclude<keyof VisaMasterSettingFormData, "isActive">) => (value: string) => {
|
||||
setValue(key, value);
|
||||
clearErrors(key);
|
||||
},
|
||||
@@ -100,20 +101,21 @@ export function VisaMasterSettingForm({ mode, initialData }: VisaMasterSettingFo
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = buildPayload(getValues());
|
||||
const values = getValues();
|
||||
|
||||
if (mode === "create") {
|
||||
await createMutation.mutateAsync(payload);
|
||||
navigate("/resources/visa-master-settings");
|
||||
} else {
|
||||
await updateMutation.mutateAsync(payload);
|
||||
navigate("/resources/visa-master-settings");
|
||||
try {
|
||||
if (mode === "create") {
|
||||
await createMutation.mutateAsync(buildCreatePayload(values));
|
||||
} else {
|
||||
await updateMutation.mutateAsync(buildUpdatePayload(values));
|
||||
}
|
||||
navigate(LIST_PATH);
|
||||
} catch {
|
||||
// error toast is handled in the mutation hooks
|
||||
}
|
||||
}, [mode, createMutation, updateMutation, navigate, trigger, getValues, t]);
|
||||
|
||||
const handleCancel = () => navigate("/resources/visa-master-settings");
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
const handleCancel = () => navigate(LIST_PATH);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
@@ -122,16 +124,17 @@ export function VisaMasterSettingForm({ mode, initialData }: VisaMasterSettingFo
|
||||
? t("visaMasterSettings.createTitle", "Visa/Master, Sber sazlamalar dörediň")
|
||||
: t("visaMasterSettings.editTitle", "Visa/Master, Sber sazlamalar üýtgetmek")}
|
||||
</h1>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("visaMasterSettings.fields.kod", "Kod")}
|
||||
value={form.kod}
|
||||
onChange={set("kod")}
|
||||
value={form.code}
|
||||
onChange={set("code")}
|
||||
placeholder={t("visaMasterSettings.fields.kod", "Kod")}
|
||||
error={errMsg(errors.kod)}
|
||||
disabled={isPending}
|
||||
error={errMsg(errors.code)}
|
||||
disabled={isPending || mode === "edit"}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -139,28 +142,65 @@ export function VisaMasterSettingForm({ mode, initialData }: VisaMasterSettingFo
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("visaMasterSettings.fields.ady", "Ady")}
|
||||
value={form.ady}
|
||||
onChange={set("ady")}
|
||||
value={form.name}
|
||||
onChange={set("name")}
|
||||
placeholder={t("visaMasterSettings.fields.ady", "Ady")}
|
||||
error={errMsg(errors.ady)}
|
||||
error={errMsg(errors.name)}
|
||||
disabled={isPending}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t("visaMasterSettings.fields.yazgy", "Yazgy")}
|
||||
value={form.yazgy}
|
||||
onChange={set("yazgy")}
|
||||
placeholder={t("visaMasterSettings.fields.yazgy", "Yazgy")}
|
||||
error={errMsg(errors.yazgy)}
|
||||
label={t("visaMasterSettings.fields.textTm", "Tekst (TM)")}
|
||||
value={form.textTm}
|
||||
onChange={set("textTm")}
|
||||
placeholder={t("visaMasterSettings.fields.textTm", "Tekst (TM)")}
|
||||
error={errMsg(errors.textTm)}
|
||||
disabled={isPending}
|
||||
rows={3}
|
||||
required
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t("visaMasterSettings.fields.textRu", "Tekst (RU)")}
|
||||
value={form.textRu}
|
||||
onChange={set("textRu")}
|
||||
placeholder={t("visaMasterSettings.fields.textRu", "Tekst (RU)")}
|
||||
error={errMsg(errors.textRu)}
|
||||
disabled={isPending}
|
||||
rows={3}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="textarea"
|
||||
label={t("visaMasterSettings.fields.textEn", "Tekst (EN)")}
|
||||
value={form.textEn}
|
||||
onChange={set("textEn")}
|
||||
placeholder={t("visaMasterSettings.fields.textEn", "Tekst (EN)")}
|
||||
error={errMsg(errors.textEn)}
|
||||
disabled={isPending}
|
||||
rows={3}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<label className="flex items-center gap-2 text-sm text-foreground cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="h-4 w-4"
|
||||
checked={form.isActive}
|
||||
disabled={isPending}
|
||||
onChange={(e) => setValue("isActive", e.target.checked)}
|
||||
/>
|
||||
{t("visaMasterSettings.fields.isActive", "Aktiw")}
|
||||
</label>
|
||||
<FormActions
|
||||
isPending={isPending}
|
||||
onSubmit={handleSubmit}
|
||||
|
||||
Reference in new issue
Block a user