fixed some ux components, added constants
This commit is contained in:
1 parent
6da59f42d9
commit
5073166931
30 files changed
+409
-425
No files matched your search
@@ -7,7 +7,7 @@ import { CreditCard, User, FileText, MapPin } from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { FormInput, type SelectOption } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
@@ -15,6 +15,11 @@ import type { CardOrder } from "../api/orderNewCardApi";
|
||||
import { useCreateCard, useUpdateCard } from "../hooks/useOrderNewCard";
|
||||
import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/orderNewCard.schema";
|
||||
import type { OrderNewCardFormData } from "../schemas/orderNewCard.schema";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { useCardReasons } from "@/features/cardReasons/hooks/useCardReasons";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -94,19 +99,16 @@ interface StepContentProps {
|
||||
errors: FlatErrors;
|
||||
set: <K extends keyof OrderNewCardFormData>(k: K, v: OrderNewCardFormData[K]) => void;
|
||||
t: TFunction;
|
||||
cardTypeOptions: SelectOption[];
|
||||
cardStateOptions: SelectOption[];
|
||||
branchOptions: SelectOption[];
|
||||
districtOptions: SelectOption[];
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
|
||||
function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
const STATUS_OPTIONS = useMemo(
|
||||
() => [
|
||||
{ value: "PENDING", label: t("cardOrder.status.pending", "Garaşylýar") },
|
||||
{ value: "APPROVED", label: t("cardOrder.status.approved", "Tassyklandy") },
|
||||
{ value: "REJECTED", label: t("cardOrder.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
[t],
|
||||
);
|
||||
function StepCard({ form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions }: StepContentProps) {
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "cardOrder.status"), [t]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
@@ -118,7 +120,7 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
required
|
||||
value={form.status}
|
||||
onChange={(v) => set("status", v)}
|
||||
options={STATUS_OPTIONS}
|
||||
options={statusOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.status}
|
||||
/>
|
||||
@@ -169,42 +171,46 @@ function StepCard({ form, errors, set, t }: StepContentProps) {
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardInfo") || "Kart maglumatlary"}>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.cardTypeId", "Kart görnüşi ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.cardTypeId", "Kart görnüşi")}
|
||||
required
|
||||
value={form.cardTypeId}
|
||||
onChange={(v) => set("cardTypeId", v)}
|
||||
placeholder={t("cardOrder.field.cardTypeId", "Kart görnüşi ID")}
|
||||
options={cardTypeOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardTypeId}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.cardStateId", "Kart ýagdaýy ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.cardStateId", "Kart ýagdaýy")}
|
||||
required
|
||||
value={form.cardStateId}
|
||||
onChange={(v) => set("cardStateId", v)}
|
||||
placeholder={t("cardOrder.field.cardStateId", "Kart ýagdaýy ID")}
|
||||
options={cardStateOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.cardStateId}
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("cardPinForm.titles.location") || "Lokasiýa"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.region", "Sebit")}
|
||||
required
|
||||
value={form.region}
|
||||
onChange={(v) => set("region", v)}
|
||||
placeholder={t("cardOrder.field.region", "Sebit")}
|
||||
options={districtOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.region}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.branchId", "Şahamça ID")}
|
||||
type="searchable-select"
|
||||
label={t("cardOrder.field.branchId", "Şahamça")}
|
||||
required
|
||||
value={form.branchId}
|
||||
onChange={(v) => set("branchId", v)}
|
||||
placeholder={t("cardOrder.field.branchId", "Şahamça ID")}
|
||||
options={branchOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.branchId}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -323,12 +329,13 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
type="select"
|
||||
label={t("cardOrder.field.passportSerie", "Pasport seriýasy")}
|
||||
required
|
||||
value={form.passportSerie}
|
||||
onChange={(v) => set("passportSerie", v)}
|
||||
placeholder={t("cardOrder.field.passportSerie", "Pasport seriýasy")}
|
||||
options={PASSPORT_SERIES_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.passportSerie}
|
||||
/>
|
||||
</BentoCard>
|
||||
@@ -464,10 +471,53 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as "tm" | "ru" | "en";
|
||||
|
||||
const createMutation = useCreateCard();
|
||||
const updateMutation = useUpdateCard(initialData?.id ?? 0);
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const { data: cardTypesData } = useCardTypes({ page: 1, limit: 100 });
|
||||
const { data: cardReasonsData } = useCardReasons({ page: 1, limit: 100 });
|
||||
const { data: branchesData } = useBranches({ page: 1, limit: 100 });
|
||||
const { data: districtsData } = useDistricts({ page: 1, limit: 100 });
|
||||
|
||||
const cardTypeOptions = useMemo(
|
||||
() =>
|
||||
(cardTypesData?.paymentCards ?? []).map((ct) => ({
|
||||
value: String(ct.id),
|
||||
label: ct.title[lang] || ct.title.tm,
|
||||
})),
|
||||
[cardTypesData, lang],
|
||||
);
|
||||
|
||||
const cardStateOptions = useMemo(
|
||||
() =>
|
||||
(cardReasonsData?.reasonCards ?? []).map((cr) => ({
|
||||
value: String(cr.id),
|
||||
label: cr.title[lang] || cr.title.tm,
|
||||
})),
|
||||
[cardReasonsData, lang],
|
||||
);
|
||||
|
||||
const branchOptions = useMemo(
|
||||
() =>
|
||||
(branchesData?.branches ?? []).map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name[lang] || b.name.tm,
|
||||
})),
|
||||
[branchesData, lang],
|
||||
);
|
||||
|
||||
const districtOptions = useMemo(
|
||||
() =>
|
||||
(districtsData?.provinces ?? []).map((d) => ({
|
||||
value: d.region?.tm || d.name.tm,
|
||||
label: d.name[lang] || d.name.tm,
|
||||
})),
|
||||
[districtsData, lang],
|
||||
);
|
||||
|
||||
const {
|
||||
watch,
|
||||
setValue,
|
||||
@@ -519,7 +569,10 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
return { ...fromRHF, ...allSubmittedErrors };
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t }), [form, errors, set, t]);
|
||||
const stepProps = useMemo(
|
||||
() => ({ form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions }),
|
||||
[form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions],
|
||||
);
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in new issue
Block a user