added role func, fixed some ui

This commit is contained in:
Jelaletdin12 committed 2026-09-01 23:35:17 +05:00
1 parent cc5b5fca24
commit 7445e09d5f
22 files changed
+1074 -622

No files matched your search

@@ -21,7 +21,7 @@ import { useInfiniteLoanTypes } from "@/features/loanTypes/hooks/useLoanTypes";
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
import { useInfiniteProvinces } from "@/features/branches/hooks/useBranches";
import type { LocalizedText } from "@/features/branches/api/branchesApi";
import { formatFromApiDate, formatFromApiPhone } from "@/lib/utils";
import { formatFromApiDateInput, formatFromApiPhone } from "@/lib/utils";
import {
PASSPORT_SERIES_OPTIONS,
getStatusOptions,
@@ -33,6 +33,7 @@ import {
} from "@/constants";
import { useGetRequiredDocuments } from "@/features/requiredDocuments/hooks/useRequiredDocuments";
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock";
// ─── Static options ───────────────────────────────────────────────────────────
@@ -378,9 +379,18 @@ function StepLocation({ form, errors, set, t, initialData }: StepContentProps &
);
}
function StepPersonal({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) {
function StepPersonal({
form,
errors,
set,
t,
initialData,
userLocked,
selfUserId,
userName,
}: StepContentProps & { initialData?: LoanOrder; userLocked?: boolean; selfUserId?: string; userName?: string }) {
const [clientSearch, setClientSearch] = useState("");
const clientsQuery = useInfiniteClients(clientSearch);
const clientsQuery = useInfiniteClients(clientSearch, !userLocked);
const clientOptions: InfiniteSelectOption[] = useMemo(() => {
const opts: InfiniteSelectOption[] = (clientsQuery.data?.pages ?? [])
@@ -388,7 +398,12 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
.map((u) => ({
value: String(u.id),
label: u.name || `${u.firstName || ""} ${u.lastName || ""}`.trim() || u.username || String(u.id),
}));
}))
.filter((o) => !userLocked || o.value === selfUserId);
if (selfUserId && !opts.some((o) => o.value === selfUserId)) {
opts.unshift({ value: selfUserId, label: userName || selfUserId });
}
if (initialData?.createdById && !opts.some((o) => o.value === String(initialData.createdById))) {
opts.unshift({
@@ -397,7 +412,7 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
});
}
return opts;
}, [clientsQuery.data, initialData]);
}, [clientsQuery.data, initialData, userLocked, selfUserId, userName]);
return (
<div className="space-y-4">
@@ -417,6 +432,7 @@ function StepPersonal({ form, errors, set, t, initialData }: StepContentProps &
onLoadMore={() => clientsQuery.fetchNextPage()}
searchValue={clientSearch}
onSearchChange={setClientSearch}
disabled={userLocked}
/>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
<FormInput
@@ -1075,6 +1091,8 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
const updateMutation = useUpdateLoanOrder();
const isPending = createMutation.isPending || updateMutation.isPending;
const { locked: userLocked, userId: selfUserId, userName } = useWebSelfLock(true);
const {
watch,
setValue,
@@ -1083,7 +1101,9 @@ export function LoanOrderForm({ mode, initialData }: LoanOrderFormProps) {
clearErrors,
setError,
} = useForm<LoanOrderFormData>({
defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) } : DEFAULT_FORM_VALUES,
defaultValues: initialData
? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData), ...(userLocked ? { userId: selfUserId } : {}) }
: { ...DEFAULT_FORM_VALUES, userId: selfUserId },
});
const form = watch();
@@ -1233,7 +1253,9 @@ 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} initialData={initialData} />}
{currentStep === 3 && (
<StepPersonal {...stepProps} initialData={initialData} userLocked={userLocked} selfUserId={selfUserId} userName={userName} />
)}
{currentStep === 4 && <StepCard {...stepProps} />}
{currentStep === 5 && <StepPassport {...stepProps} mode={mode} />}
{currentStep === 6 && <StepContact {...stepProps} />}
@@ -1285,7 +1307,7 @@ function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
customerPatronicName: order.customerPatronicName ?? order.patronicName ?? "",
education: order.education ?? "",
marriageStatus: order.marriageStatus ?? "",
bornAt: formatFromApiDate(order.bornAt ?? order.dateOfBirth),
bornAt: formatFromApiDateInput(order.bornAt ?? order.dateOfBirth),
bornPlace: order.bornPlace ?? "",
passportAddress: order.passportAddress ?? order.residence ?? "",
realAddress: order.realAddress ?? order.currentResidence ?? "",
@@ -1295,7 +1317,7 @@ function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
cardYear: order.cardYear ?? order.cardExpYear ?? "",
passportSerie: order.passportSerie ?? "",
passportId: order.passportId ?? order.passportNumber ?? "",
passportGivenAt: formatFromApiDate(order.passportGivenAt ?? order.passportDateOfIssue),
passportGivenAt: formatFromApiDateInput(order.passportGivenAt ?? order.passportDateOfIssue),
passportGivenBy: order.passportGivenBy ?? "",
passportOne: order.passportOne ?? order.passportPage1Url ?? "",
passportTwo: order.passportTwo ?? order.passportPage23Url ?? "",
@@ -1311,7 +1333,7 @@ function mapInitial(order: LoanOrder): Partial<LoanOrderFormData> {
workProvinceId: order.workProvinceId != null ? String(order.workProvinceId) : order.workCityId != null ? String(order.workCityId) : "",
workPosition: order.workPosition ?? order.position ?? "",
workSalary: order.workSalary != null ? String(order.workSalary) : order.salary != null ? String(order.salary) : "",
workStartedAt: formatFromApiDate(order.workStartedAt),
workStartedAt: formatFromApiDateInput(order.workStartedAt),
guarantorName: order.guarantorName ?? order.guarantor1Name ?? "",
guarantorSurname: order.guarantorSurname ?? order.guarantor1Surname ?? "",
guarantorPatronicName: order.guarantorPatronicName ?? order.guarantor1Patronic ?? "",