added missed json keys

This commit is contained in:
Jelaletdin12 committed 2026-09-02 18:28:24 +05:00
1 parent 7445e09d5f
commit 25c104ad8c
12 files changed
+558 -194

No files matched your search

@@ -20,6 +20,7 @@ import type { CardRequisiteFormData } from "../schemas/cardRequisite.schema";
import { useInfiniteCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
import { useInfiniteBranches } from "@/features/branches/hooks/useBranches";
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock";
import { resolveLocalizedName } from "@/features/loanOrders/api/loanOrdersApi";
import { getRegionOptions, MONTH_OPTIONS, CARD_YEAR_OPTIONS } from "@/constants";
@@ -135,18 +136,21 @@ interface StepContentProps {
set: <K extends keyof CardRequisiteFormData>(k: K, v: CardRequisiteFormData[K]) => void;
t: TFunction;
initialData?: CardRequisite;
userLocked: boolean;
selfUserId: string;
userName: string;
}
// ─── Step panels ──────────────────────────────────────────────────────────────
function StepCard({ form, errors, set, t, initialData }: StepContentProps) {
function StepCard({ form, errors, set, t, initialData, userLocked, selfUserId, userName }: StepContentProps) {
const [cardTypeSearch, setCardTypeSearch] = useState("");
const [branchSearch, setBranchSearch] = useState("");
const [clientSearch, setClientSearch] = useState("");
const cardTypeQuery = useInfiniteCardTypes(cardTypeSearch);
const branchQuery = useInfiniteBranches(branchSearch);
const clientQuery = useInfiniteClients(clientSearch);
const clientQuery = useInfiniteClients(clientSearch, !userLocked);
const regionOptions = useMemo(() => getRegionOptions(t, "cardRequisites"), [t]);
@@ -180,161 +184,175 @@ function StepCard({ form, errors, set, t, initialData }: StepContentProps) {
const clientOptions: InfiniteSelectOption[] = useMemo(() => {
const opts: InfiniteSelectOption[] = (clientQuery.data?.pages ?? [])
.flatMap((p) => p?.users ?? [])
.map((u) => ({ value: String(u.id), label: u.name || u.username || String(u.id) }));
.map((u) => ({ value: String(u.id), label: u.name || 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 });
}
if (initialData?.user?.id && !opts.some((o) => o.value === String(initialData.user.id))) {
opts.unshift({ value: String(initialData.user.id), label: initialData.user.name || String(initialData.user.id) });
}
return opts;
}, [clientQuery, initialData]);
}, [clientQuery, initialData, userLocked, selfUserId, userName]);
return (
<div className="space-y-4">
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="select"
label={t("cardRequisiteForm.labels.status") || "Statusy"}
required
value={form.status}
onChange={(v) => set("status", v)}
options={STATUS_OPTIONS}
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
error={errors.status}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("cardRequisiteForm.labels.uniqueId") || "Sargyt belgisi (Unikal ID)"}
value={form.uniqueId}
onChange={(v) => set("uniqueId", v)}
placeholder={t("cardRequisiteForm.placeholders.uniqueId") || "Unikal ID..."}
error={errors.uniqueId}
/>
</BentoCard>
</BentoGrid>
<div className="space-y-6">
{/* ── Sargyt maglumatlary ─────────────────────────────────────── */}
<div className="space-y-3">
<h3 className="text-sm font-medium text-muted-foreground">{t("cardRequisiteForm.sections.order") || "Sargyt maglumatlary"}</h3>
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="select"
label={t("cardRequisiteForm.labels.status") || "Statusy"}
required
value={form.status}
onChange={(v) => set("status", v)}
options={STATUS_OPTIONS}
placeholder={t("loanOrderForm.placeholders.select") || "Saýlaň"}
error={errors.status}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("cardRequisiteForm.labels.uniqueId") || "Sargyt belgisi (Unikal ID)"}
value={form.uniqueId}
onChange={(v) => set("uniqueId", v)}
placeholder={t("cardRequisiteForm.placeholders.uniqueId") || "Unikal ID..."}
error={errors.uniqueId}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("Note") || "Bellik"}
value={form.notes}
onChange={(v) => set("notes", v)}
placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."}
/>
</BentoCard>
</BentoGrid>
</div>
<BentoGrid cols={2}>
<BentoCard>
<InfiniteSelect
label={t("cardRequisiteForm.labels.cardType") || "Kart görnüşi"}
value={form.cardTypeId}
onChange={(v) => set("cardTypeId", v)}
options={cardTypeOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
loading={cardTypeQuery.isLoading}
isLoadingMore={cardTypeQuery.isFetchingNextPage}
hasNextPage={!!cardTypeQuery.hasNextPage}
onLoadMore={() => cardTypeQuery.fetchNextPage()}
searchValue={cardTypeSearch}
onSearchChange={setCardTypeSearch}
error={errors.cardTypeId}
required
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("cardRequisiteForm.labels.cardNumber") || "Kart belgisi"}
value={form.cardNumber}
onChange={(v) => set("cardNumber", v)}
placeholder="9800 0000 0000 0000"
error={errors.cardNumber}
/>
</BentoCard>
</BentoGrid>
{/* ── Kart maglumatlary ───────────────────────────────────────── */}
<div className="space-y-3">
<h3 className="text-sm font-medium text-muted-foreground">{t("cardRequisiteForm.sections.card") || "Kart maglumatlary"}</h3>
<BentoGrid cols={2}>
<BentoCard>
<InfiniteSelect
label={t("cardRequisiteForm.labels.cardType") || "Kart görnüşi"}
value={form.cardTypeId}
onChange={(v) => set("cardTypeId", v)}
options={cardTypeOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
loading={cardTypeQuery.isLoading}
isLoadingMore={cardTypeQuery.isFetchingNextPage}
hasNextPage={!!cardTypeQuery.hasNextPage}
onLoadMore={() => cardTypeQuery.fetchNextPage()}
searchValue={cardTypeSearch}
onSearchChange={setCardTypeSearch}
error={errors.cardTypeId}
required
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("cardRequisiteForm.labels.cardNumber") || "Kart belgisi"}
value={form.cardNumber}
onChange={(v) => set("cardNumber", v)}
placeholder="9800 0000 0000 0000"
error={errors.cardNumber}
/>
</BentoCard>
</BentoGrid>
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="searchable-select"
label={t("loanOrderForm.labels.cardExpMonth") || "Aý"}
required
value={form.cardMonth}
onChange={(v) => set("cardMonth", v)}
options={MONTH_OPTIONS}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
error={errors.cardMonth}
/>
</BentoCard>
<BentoCard>
<FormInput
type="searchable-select"
label={t("loanOrderForm.labels.cardExpYear") || "Ýyl"}
required
value={form.cardYear}
onChange={(v) => set("cardYear", v)}
options={CARD_YEAR_OPTIONS}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
error={errors.cardYear}
/>
</BentoCard>
</BentoGrid>
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="searchable-select"
label={t("loanOrderForm.labels.cardExpMonth") || "Aý"}
required
value={form.cardMonth}
onChange={(v) => set("cardMonth", v)}
options={MONTH_OPTIONS}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
error={errors.cardMonth}
/>
</BentoCard>
<BentoCard>
<FormInput
type="searchable-select"
label={t("loanOrderForm.labels.cardExpYear") || "Ýyl"}
required
value={form.cardYear}
onChange={(v) => set("cardYear", v)}
options={CARD_YEAR_OPTIONS}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
error={errors.cardYear}
/>
</BentoCard>
</BentoGrid>
</div>
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="searchable-select"
label={t("Region") || "Welaýat"}
required
value={form.region}
onChange={(v) => {
set("region", v);
set("branchId", "");
}}
options={regionOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
error={errors.region}
/>
</BentoCard>
<BentoCard>
<InfiniteSelect
label={t("Branch") || "Şahamça"}
value={form.branchId}
onChange={(v) => set("branchId", v)}
options={branchOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
loading={branchQuery.isLoading}
isLoadingMore={branchQuery.isFetchingNextPage}
hasNextPage={!!branchQuery.hasNextPage}
onLoadMore={() => branchQuery.fetchNextPage()}
searchValue={branchSearch}
onSearchChange={setBranchSearch}
disabled={!form.region}
error={errors.branchId}
required
/>
</BentoCard>
</BentoGrid>
<BentoGrid cols={2}>
<BentoCard>
<InfiniteSelect
label={t("cardRequisiteForm.labels.user") || "Ulanyjy"}
value={form.userId}
onChange={(v) => set("userId", v)}
options={clientOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
loading={clientQuery.isLoading}
isLoadingMore={clientQuery.isFetchingNextPage}
hasNextPage={!!clientQuery.hasNextPage}
onLoadMore={() => clientQuery.fetchNextPage()}
searchValue={clientSearch}
onSearchChange={setClientSearch}
error={errors.userId}
required
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("Note") || "Bellik"}
value={form.notes}
onChange={(v) => set("notes", v)}
placeholder={t("loanOrderForm.placeholders.note") || "Bellik..."}
/>
</BentoCard>
</BentoGrid>
{/* ── Ýerleşiş & Ulanyjy ──────────────────────────────────────── */}
<div className="space-y-3">
<h3 className="text-sm font-medium text-muted-foreground">{t("cardRequisiteForm.sections.location") || "Ýerleşiş & Ulanyjy"}</h3>
<BentoGrid cols={3}>
<BentoCard>
<FormInput
type="searchable-select"
label={t("Region") || "Welaýat"}
required
value={form.region}
onChange={(v) => {
set("region", v);
set("branchId", "");
}}
options={regionOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
error={errors.region}
/>
</BentoCard>
<BentoCard>
<InfiniteSelect
label={t("Branch") || "Şahamça"}
value={form.branchId}
onChange={(v) => set("branchId", v)}
options={branchOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
loading={branchQuery.isLoading}
isLoadingMore={branchQuery.isFetchingNextPage}
hasNextPage={!!branchQuery.hasNextPage}
onLoadMore={() => branchQuery.fetchNextPage()}
searchValue={branchSearch}
onSearchChange={setBranchSearch}
disabled={!form.region}
error={errors.branchId}
required
/>
</BentoCard>
<BentoCard>
<InfiniteSelect
label={t("cardRequisiteForm.labels.user") || "Ulanyjy"}
value={form.userId}
onChange={(v) => set("userId", v)}
options={clientOptions}
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
disabled={userLocked}
loading={clientQuery.isLoading}
isLoadingMore={clientQuery.isFetchingNextPage}
hasNextPage={!!clientQuery.hasNextPage}
onLoadMore={() => clientQuery.fetchNextPage()}
searchValue={clientSearch}
onSearchChange={setClientSearch}
error={errors.userId}
required
/>
</BentoCard>
</BentoGrid>
</div>
</div>
);
}
@@ -480,6 +498,8 @@ export function CardRequisiteForm({ mode, initialData }: CardRequisiteFormProps)
const { t, i18n } = useTranslation();
const navigate = useNavigate();
const { locked: userLocked, userId: selfUserId, userName } = useWebSelfLock(true);
const createMutation = useCreateCardRequisite();
const updateMutation = useUpdateCardRequisite(initialData?.id ?? 0);
const isPending = createMutation.isPending || updateMutation.isPending;
@@ -492,7 +512,9 @@ export function CardRequisiteForm({ mode, initialData }: CardRequisiteFormProps)
clearErrors,
setError,
} = useForm<CardRequisiteFormData>({
defaultValues: initialData ? mapInitial(initialData) : DEFAULT_FORM_VALUES,
defaultValues: initialData
? { ...mapInitial(initialData), ...(userLocked ? { userId: selfUserId } : {}) }
: { ...DEFAULT_FORM_VALUES, userId: selfUserId },
});
const form = watch();
@@ -532,7 +554,10 @@ export function CardRequisiteForm({ mode, initialData }: CardRequisiteFormProps)
return { ...fromRHF, ...allSubmittedErrors };
}, [rhfErrors, allSubmittedErrors]);
const stepProps = useMemo(() => ({ form, errors, set, t, initialData }), [form, errors, set, t, initialData]);
const stepProps = useMemo(
() => ({ form, errors, set, t, initialData, userLocked, selfUserId, userName }),
[form, errors, set, t, initialData, userLocked, selfUserId, userName],
);
// ── Navigation ─────────────────────────────────────────────────────────────
@@ -206,7 +206,7 @@ function StepStatus({ form, errors, set, t }: StepContentProps) {
function StepLoan({ form, errors, set, t, initialData }: StepContentProps & { initialData?: LoanOrder }) {
const { i18n } = useTranslation();
const { data: requiredDocsData } = useGetRequiredDocuments({ page: 1, limit: 100 });
const { data: requiredDocsData } = useGetRequiredDocuments({ page: 1, limit: 25 });
const [loanTypeSearch, setLoanTypeSearch] = useState("");
const loanTypesQuery = useInfiniteLoanTypes(loanTypeSearch);
@@ -15,7 +15,7 @@ import { StepBarCards, type StepCardItem } from "@/components/stepBarV2";
import { BentoGrid, BentoCard } from "@/components/bento";
import { PASSPORT_SERIES_OPTIONS, getStatusOptions, getRegionOptions, LOAN_PAID_OFF_REGION_CODES } from "@/constants";
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock";
import type { LocalizedText } from "@/features/branches/api/branchesApi";
@@ -376,10 +376,10 @@ export function LoanPaidOffLetterForm({ mode, initialData }: LoanPaidOffLetterFo
// ── User infinite-scroll select ──
const [userSearch, setUserSearch] = useState("");
const usersQuery = useInfiniteUsers(userSearch, !userLocked);
const clientsQuery = useInfiniteClients(userSearch, !userLocked);
const userSelectProps: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
const opts: InfiniteSelectOption[] = (usersQuery.data?.pages ?? [])
const opts: InfiniteSelectOption[] = (clientsQuery.data?.pages ?? [])
.flatMap((p) => p?.users ?? [])
.map((u) => {
const displayName = [u.firstName, u.lastName].filter(Boolean).join(" ") || u.name || u.username;
@@ -404,14 +404,14 @@ export function LoanPaidOffLetterForm({ mode, initialData }: LoanPaidOffLetterFo
return {
options: opts,
loading: usersQuery.isLoading,
isLoadingMore: usersQuery.isFetchingNextPage,
hasNextPage: !!usersQuery.hasNextPage,
onLoadMore: () => usersQuery.fetchNextPage(),
loading: clientsQuery.isLoading,
isLoadingMore: clientsQuery.isFetchingNextPage,
hasNextPage: !!clientsQuery.hasNextPage,
onLoadMore: () => clientsQuery.fetchNextPage(),
searchValue: userSearch,
onSearchChange: setUserSearch,
};
}, [usersQuery, userSearch, initialData, userLocked, selfUserId, userName]);
}, [clientsQuery, userSearch, initialData, userLocked, selfUserId, userName]);
const {
watch,
@@ -171,7 +171,7 @@ export function LoanRemainingForm({ mode, initialData }: LoanRemainingFormProps)
required
value={watch("userId")}
onChange={(v) => setValue("userId", v, { shouldValidate: true })}
placeholder={t("loanRemaining.placeholders.userId", "Ulanyjy saýlaň")}
placeholder={t("Select", "Ulanyjy saýlaň")}
error={errMsg(errors.userId?.message)}
disabled={isPending || userLocked}
{...userSelectProps}
+1 -1
View File
@@ -45,7 +45,7 @@ const LOAN_TYPE_PAGE_SIZE = 25;
*/
export function useInfiniteLoanTypes(search = "") {
const debouncedSearch = useDebouncedValue(search);
const effectiveSearch = normalizeSearch(debouncedSearch);
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
return useInfiniteQuery({
queryKey: [...loanTypeKeys.all(), "infinite", effectiveSearch] as const,
@@ -287,10 +287,10 @@ export function OperatorForm({ mode, initialData }: OperatorFormProps) {
{...roleSelect}
/>
<InfiniteSelect
label={t("users.fields.branch", "Şahamça")}
label={t("Branch", "Şahamça")}
value={selectedBranchId}
onChange={(branchId) => setSelectedBranchId(branchId)}
placeholder={t("users.fields.branchPlaceholder", "Şahamça saýlaň")}
placeholder={t("loanOrderForm.placeholders.select", "Şahamça saýlaň")}
disabled={isPending}
{...branchSelect}
/>