fixed ui, connected role user, branch user permissions user api
This commit is contained in:
1 parent
d230b12d6a
commit
f00d2abcac
20 files changed
+906
-391
No files matched your search
@@ -23,6 +23,8 @@ import { useInfiniteProvinces } from "@/features/branches/hooks/useBranches";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { formatFromApiDate, formatFromApiPhone } from "@/lib/utils";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions } from "@/constants";
|
||||
import { useGetRequiredDocuments } from "@/features/requiredDocuments/hooks/useRequiredDocuments";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
|
||||
// ─── Static options ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -344,81 +346,124 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps &
|
||||
);
|
||||
}
|
||||
|
||||
function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
function StepPersonal({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) {
|
||||
const { data: requiredDocsData } = useGetRequiredDocuments({ page: 1, limit: 100 });
|
||||
|
||||
const [clientSearch, setClientSearch] = useState("");
|
||||
const clientsQuery = useInfiniteClients(clientSearch);
|
||||
|
||||
const clientOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
const opts: InfiniteSelectOption[] = (clientsQuery.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?.createdById && !opts.some((o) => o.value === String(initialData.createdById))) {
|
||||
opts.unshift({
|
||||
value: String(initialData.createdById),
|
||||
label: initialData.createdBy || String(initialData.createdById),
|
||||
});
|
||||
}
|
||||
return opts;
|
||||
}, [clientsQuery.data, initialData]);
|
||||
|
||||
const loanHistoryOptions = useMemo<SelectOption[]>(
|
||||
() =>
|
||||
(requiredDocsData?.loansDocuments ?? []).map((doc) => ({
|
||||
value: String(doc.id),
|
||||
label: doc.name,
|
||||
})),
|
||||
[requiredDocsData],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Name") || "Ady"}
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t("loanOrderForm.titles.personalName") || "Şahsy maglumatlar"}>
|
||||
<InfiniteSelect
|
||||
label={t("loanOrderForm.labels.client") || "Müşderi"}
|
||||
required
|
||||
value={form.firstName}
|
||||
onChange={(v) => set("firstName", v)}
|
||||
placeholder={t("Name") || "Ady"}
|
||||
error={errors.firstName}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Surname") || "Familiýasy"}
|
||||
required
|
||||
value={form.lastName}
|
||||
onChange={(v) => set("lastName", v)}
|
||||
placeholder={t("Surname") || "Familiýasy"}
|
||||
error={errors.lastName}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Patronic name") || "Atasynyň ady"}
|
||||
value={form.patronicName}
|
||||
onChange={(v) => set("patronicName", v)}
|
||||
placeholder={t("Patronic name") || "Atasynyň ady"}
|
||||
value={form.userId}
|
||||
onChange={(v) => set("userId", v)}
|
||||
options={clientOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.userId}
|
||||
loading={clientsQuery.isLoading}
|
||||
isLoadingMore={clientsQuery.isFetchingNextPage}
|
||||
hasNextPage={!!clientsQuery.hasNextPage}
|
||||
onLoadMore={() => clientsQuery.fetchNextPage()}
|
||||
searchValue={clientSearch}
|
||||
onSearchChange={setClientSearch}
|
||||
/>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Name") || "Ady"}
|
||||
required
|
||||
value={form.firstName}
|
||||
onChange={(v) => set("firstName", v)}
|
||||
placeholder={t("Name") || "Ady"}
|
||||
error={errors.firstName}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Surname") || "Familiýasy"}
|
||||
required
|
||||
value={form.lastName}
|
||||
onChange={(v) => set("lastName", v)}
|
||||
placeholder={t("Surname") || "Familiýasy"}
|
||||
error={errors.lastName}
|
||||
/>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Patronic name") || "Atasynyň ady"}
|
||||
value={form.patronicName}
|
||||
onChange={(v) => set("patronicName", v)}
|
||||
placeholder={t("Patronic name") || "Atasynyň ady"}
|
||||
/>
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={3}>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("Education") || "Bilimi"}
|
||||
required
|
||||
value={form.education}
|
||||
onChange={(v) => set("education", v)}
|
||||
options={EDUCATION_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.education}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("Marriage status") || "Maşgala ýagdaýy"}
|
||||
required
|
||||
value={form.marriageStatus}
|
||||
onChange={(v) => set("marriageStatus", v)}
|
||||
options={MARRIAGE_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.marriageStatus}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t("Date of birth") || "Doglan güni"}
|
||||
required
|
||||
value={form.dateOfBirth}
|
||||
onChange={(v) => set("dateOfBirth", v)}
|
||||
error={errors.dateOfBirth}
|
||||
/>
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t("loanOrderForm.titles.personalDetails") || "Bilim we maşgala ýagdaýy"}>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("Education") || "Bilimi"}
|
||||
required
|
||||
value={form.education}
|
||||
onChange={(v) => set("education", v)}
|
||||
options={EDUCATION_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.education}
|
||||
/>
|
||||
<FormInput
|
||||
type="select"
|
||||
label={t("Marriage status") || "Maşgala ýagdaýy"}
|
||||
required
|
||||
value={form.marriageStatus}
|
||||
onChange={(v) => set("marriageStatus", v)}
|
||||
options={MARRIAGE_OPTIONS}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
error={errors.marriageStatus}
|
||||
/>
|
||||
<FormInput
|
||||
type="date"
|
||||
label={t("Date of birth") || "Doglan güni"}
|
||||
required
|
||||
value={form.dateOfBirth}
|
||||
onChange={(v) => set("dateOfBirth", v)}
|
||||
error={errors.dateOfBirth}
|
||||
/>
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard>
|
||||
<BentoCard title={t("loanOrderForm.titles.residence") || "Ýaşaýyş salgysy"}>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Residence (passport)") || "Ýazgy edilen salgyňyz"}
|
||||
@@ -428,8 +473,6 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("loanOrderForm.placeholders.residence") || "Ýazgy edilen salgy"}
|
||||
error={errors.residence}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
<FormInput
|
||||
type="text"
|
||||
label={t("Current Residence") || "Häzirki ýaşaýyş ýeri"}
|
||||
@@ -438,14 +481,15 @@ function StepPersonal({ form, errors, set, t }: StepContentProps) {
|
||||
placeholder={t("loanOrderForm.placeholders.currentResidence") || "Häzirki ýaşaýyş ýeri"}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard span="full">
|
||||
|
||||
<BentoCard title={t("loanOrderForm.titles.loanHistory") || "Karz taryhy"}>
|
||||
<FormInput
|
||||
type="searchable-select"
|
||||
type="select"
|
||||
label={t("Loan history") || "Karz taryhy"}
|
||||
value={form.loanHistory}
|
||||
onChange={(v) => set("loanHistory", v)}
|
||||
options={[]}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
options={loanHistoryOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
|
||||
/>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
@@ -1174,7 +1218,7 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
|
||||
{currentStep === 0 && <StepStatus {...stepProps} />}
|
||||
{currentStep === 1 && <StepLoan {...stepProps} initialData={initialData} />}
|
||||
{currentStep === 2 && <StepLocation {...stepProps} initialData={initialData} />}
|
||||
{currentStep === 3 && <StepPersonal {...stepProps} />}
|
||||
{currentStep === 3 && <StepPersonal {...stepProps} initialData={initialData} />}
|
||||
{currentStep === 4 && <StepCard {...stepProps} />}
|
||||
{currentStep === 5 && <StepPassport {...stepProps} mode={mode} />}
|
||||
{currentStep === 6 && <StepContact {...stepProps} />}
|
||||
@@ -1206,6 +1250,7 @@ function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
|
||||
loanType: order.loanTypeId != null ? String(order.loanTypeId) : "",
|
||||
region: order.region ?? "AG",
|
||||
branch: order.branchId != null ? String(order.branchId) : "",
|
||||
userId: order.createdById != null ? String(order.createdById) : "",
|
||||
firstName: order.firstName ?? "",
|
||||
lastName: order.lastName ?? "",
|
||||
patronicName: order.patronicName ?? "",
|
||||
|
||||
Reference in new issue
Block a user