fixed ui, connected role user, branch user permissions user api
This commit is contained in:
@@ -9,6 +9,8 @@ import { useForm } from "react-hook-form";
|
||||
|
||||
import { FormInput, type SelectOption } from "@/components/formInput";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { DocumentUpload } from "@/components/documentUpload";
|
||||
import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infiniteSelect";
|
||||
import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
|
||||
import { BentoGrid, BentoCard } from "@/components/bento";
|
||||
import type { CardOrder } from "../api/orderNewCardApi";
|
||||
@@ -19,6 +21,7 @@ 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 { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
@@ -103,6 +106,7 @@ interface StepContentProps {
|
||||
cardStateOptions: SelectOption[];
|
||||
branchOptions: SelectOption[];
|
||||
districtOptions: SelectOption[];
|
||||
mode: "create" | "edit";
|
||||
}
|
||||
|
||||
// ─── Step panels ──────────────────────────────────────────────────────────────
|
||||
@@ -222,8 +226,8 @@ function StepCard({ form, errors, set, t, cardTypeOptions, cardStateOptions, bra
|
||||
function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("cardOrder.titles.name") || "Ady we familiýasy"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.customerName", "Ady")}
|
||||
@@ -233,8 +237,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("cardOrder.field.customerName", "Ady")}
|
||||
error={errors.customerName}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.customerSurname", "Familiýasy")}
|
||||
@@ -244,8 +246,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("cardOrder.field.customerSurname", "Familiýasy")}
|
||||
error={errors.customerSurname}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.customerPatronicName", "Atasynyň ady")}
|
||||
@@ -253,11 +253,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
onChange={(v) => set("customerPatronicName", v)}
|
||||
placeholder={t("cardOrder.field.customerPatronicName", "Atasynyň ady")}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.oldSurname", "Köne familiýaňyz (eger üýtgän bolsa)")}
|
||||
@@ -266,7 +261,8 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("cardOrder.field.oldSurname", "Köne familiýa")}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
|
||||
<BentoCard title={t("cardOrder.titles.birthInfo") || "Doglan maglumaty"}>
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t("cardOrder.field.bornAt", "Doglan güni")}
|
||||
@@ -274,8 +270,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
onChange={(v) => set("bornAt", v)}
|
||||
error={errors.bornAt}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.bornPlace", "Doglan ýeri")}
|
||||
@@ -283,11 +277,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
onChange={(v) => set("bornPlace", v)}
|
||||
placeholder={t("cardOrder.field.bornPlace", "Doglan ýeri")}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.citizenship", "Raýatlyk")}
|
||||
@@ -298,36 +287,39 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
error={errors.citizenship}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.phone", "Telefon")}
|
||||
required
|
||||
value={form.phone}
|
||||
onChange={(v) => set("phone", v)}
|
||||
placeholder={t("cardOrder.field.phone", "Telefon")}
|
||||
error={errors.phone}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.phoneAdditional", "Telefon goşmaça")}
|
||||
value={form.phoneAdditional}
|
||||
onChange={(v) => set("phoneAdditional", v)}
|
||||
placeholder={t("cardOrder.field.phoneAdditional", "Telefon goşmaça")}
|
||||
/>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t("cardOrder.titles.contact") || "Habarlaşmak"}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.phone", "Telefon")}
|
||||
required
|
||||
value={form.phone}
|
||||
onChange={(v) => set("phone", v)}
|
||||
placeholder={t("cardOrder.field.phone", "Telefon")}
|
||||
error={errors.phone}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.phoneAdditional", "Telefon goşmaça")}
|
||||
value={form.phoneAdditional}
|
||||
onChange={(v) => set("phoneAdditional", v)}
|
||||
placeholder={t("cardOrder.field.phoneAdditional", "Telefon goşmaça")}
|
||||
/>
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
function StepPassport({ form, errors, set, t, mode }: StepContentProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("loanOrderForm.titles.cardInfo") || "Pasport maglumatlary"}>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("cardOrder.field.passportSerie", "Pasport seriýasy")}
|
||||
@@ -338,8 +330,6 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.passportSerie}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportId", "Pasport belgisi")}
|
||||
@@ -349,8 +339,6 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("cardOrder.field.passportId", "Pasport belgisi")}
|
||||
error={errors.passportId}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t("cardOrder.field.passportGivenAt", "Pasport berlen senesi")}
|
||||
@@ -359,10 +347,8 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
error={errors.passportGivenAt}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<BentoCard title={t("cardOrder.titles.passportIssuer") || "Berlen ýeri"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportGivenBy", "Kim tarapyndan berildi")}
|
||||
@@ -370,8 +356,6 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
onChange={(v) => set("passportGivenBy", v)}
|
||||
placeholder={t("cardOrder.field.passportGivenBy", "Kim tarapyndan berildi")}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportAddress", "Pasport salgysy")}
|
||||
@@ -382,41 +366,52 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={4}>
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportOne", "Pasport 1")}
|
||||
<DocumentUpload
|
||||
label={
|
||||
mode === "edit"
|
||||
? t("loanOrderForm.fileLabels.replacePage1") || "Pasport (sahypa 1) (çalyşmak)"
|
||||
: t("Passport (page 1)") || "Pasport (sahypa 1)"
|
||||
}
|
||||
value={form.passportOne}
|
||||
onChange={(v) => set("passportOne", v)}
|
||||
placeholder={t("cardOrder.field.passportOne", "Pasport 1")}
|
||||
error={errors.passportOne}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportTwo", "Pasport 2")}
|
||||
<DocumentUpload
|
||||
label={
|
||||
mode === "edit"
|
||||
? t("loanOrderForm.fileLabels.replacePage23") || "Pasport (2-3-nji sahypa) (çalyşmak)"
|
||||
: t("Passport (page 2-3)") || "Pasport (2-3-nji sahypa)"
|
||||
}
|
||||
value={form.passportTwo}
|
||||
onChange={(v) => set("passportTwo", v)}
|
||||
placeholder={t("cardOrder.field.passportTwo", "Pasport 2")}
|
||||
error={errors.passportTwo}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportThree", "Pasport 3")}
|
||||
<DocumentUpload
|
||||
label={t("Passport (page 8-9)") || "Pasport (8-9 sahypa)"}
|
||||
value={form.passportThree}
|
||||
onChange={(v) => set("passportThree", v)}
|
||||
placeholder={t("cardOrder.field.passportThree", "Pasport 3")}
|
||||
error={errors.passportThree}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("cardOrder.field.passportFour", "Pasport 4")}
|
||||
<DocumentUpload
|
||||
label={t("Passport (page 32)") || "Pasport (32-nji sahypa)"}
|
||||
value={form.passportFour}
|
||||
onChange={(v) => set("passportFour", v)}
|
||||
placeholder={t("cardOrder.field.passportFour", "Pasport 4")}
|
||||
error={errors.passportFour}
|
||||
accept="image/*"
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -424,7 +419,29 @@ function StepPassport({ form, errors, set, t }: StepContentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function StepContact({ form, errors, set, t }: StepContentProps) {
|
||||
function StepContact({ form, errors, set, t, initialData }: StepContentProps & { initialData?: CardOrder }) {
|
||||
const [userSearch, setUserSearch] = useState("");
|
||||
const usersQuery = useInfiniteClients(userSearch);
|
||||
|
||||
const userOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (usersQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => ({
|
||||
value: String(u.id),
|
||||
label: u.name || `${u.firstName || ""} ${u.lastName || ""}`.trim() || u.username || String(u.id),
|
||||
}));
|
||||
|
||||
if (initialData?.userId && !opts.some((o) => o.value === String(initialData.userId))) {
|
||||
opts.unshift({
|
||||
value: String(initialData.userId),
|
||||
label: initialData.customerName
|
||||
? `${initialData.customerName} ${initialData.customerSurname || ""}`.trim()
|
||||
: String(initialData.userId),
|
||||
});
|
||||
}
|
||||
return opts;
|
||||
}, [usersQuery.data, initialData]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={2}>
|
||||
@@ -450,14 +467,20 @@ function StepContact({ form, errors, set, t }: StepContentProps) {
|
||||
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="number"
|
||||
label={t("cardOrder.field.userId", "Ulanyjy ID")}
|
||||
<InfiniteSelect
|
||||
label={t("cardOrder.field.userId", "Ulanyjy")}
|
||||
required
|
||||
value={form.userId}
|
||||
onChange={(v) => set("userId", v)}
|
||||
placeholder={t("cardOrder.field.userId", "Ulanyjy ID")}
|
||||
options={userOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.userId}
|
||||
loading={usersQuery.isLoading}
|
||||
isLoadingMore={usersQuery.isFetchingNextPage}
|
||||
hasNextPage={!!usersQuery.hasNextPage}
|
||||
onLoadMore={() => usersQuery.fetchNextPage()}
|
||||
searchValue={userSearch}
|
||||
onSearchChange={setUserSearch}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -477,10 +500,10 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
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 { data: cardTypesData } = useCardTypes({ page: 1, limit: 25 });
|
||||
const { data: cardReasonsData } = useCardReasons({ page: 1, limit: 25 });
|
||||
const { data: branchesData } = useBranches({ page: 1, limit: 25 });
|
||||
const { data: districtsData } = useDistricts({ page: 1, limit: 25 });
|
||||
|
||||
const cardTypeOptions = useMemo(
|
||||
() =>
|
||||
@@ -570,8 +593,8 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(
|
||||
() => ({ form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions }),
|
||||
[form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions],
|
||||
() => ({ form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions, mode }),
|
||||
[form, errors, set, t, cardTypeOptions, cardStateOptions, branchOptions, districtOptions, mode],
|
||||
);
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
@@ -684,7 +707,7 @@ export function CardOrderForm({ mode, initialData }: CardOrderFormProps) {
|
||||
{currentStep === 0 && <StepCard {...stepProps} />}
|
||||
{currentStep === 1 && <StepPersonal {...stepProps} />}
|
||||
{currentStep === 2 && <StepPassport {...stepProps} />}
|
||||
{currentStep === 3 && <StepContact {...stepProps} />}
|
||||
{currentStep === 3 && <StepContact {...stepProps} initialData={initialData} />}
|
||||
|
||||
{/* Actions */}
|
||||
<FormActions
|
||||
|
||||
Reference in New Issue
Block a user