added role func, fixed some ui
This commit is contained in:
@@ -19,6 +19,7 @@ import { validateStep, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/visa
|
||||
import type { IntlPaymentFormData } from "../schemas/visaMasterPayment.schema";
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteClients } from "@/features/clients/hooks/useClients";
|
||||
import { useWebSelfLock } from "@/features/shared/hooks/useWebSelfLock";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
import { PASSPORT_SERIES_OPTIONS, getStatusOptions, getRegionOptions, REGION_CODES, REGION_LABELS } from "@/constants";
|
||||
|
||||
@@ -148,11 +149,14 @@ interface StepContentProps {
|
||||
t: TFunction;
|
||||
mode: "create" | "edit";
|
||||
initialData?: IntlPaymentItem;
|
||||
userLocked: boolean;
|
||||
selfUserId: string;
|
||||
userName: string;
|
||||
}
|
||||
|
||||
function StepGeneral({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
function StepGeneral({ form, errors, set, t, initialData, userLocked, selfUserId, userName }: StepContentProps) {
|
||||
const [clientSearch, setClientSearch] = useState("");
|
||||
const clientQuery = useInfiniteClients(clientSearch);
|
||||
const clientQuery = useInfiniteClients(clientSearch, !userLocked);
|
||||
|
||||
const statusOptions = useMemo(() => getStatusOptions(t, "intlPayment.status"), [t]);
|
||||
|
||||
@@ -162,13 +166,18 @@ function StepGeneral({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
.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?.client_id && !opts.some((o) => o.value === String(initialData.client_id))) {
|
||||
opts.unshift({ value: String(initialData.client_id), label: initialData.client_label || String(initialData.client_id) });
|
||||
}
|
||||
return opts;
|
||||
}, [clientQuery.data, initialData]);
|
||||
}, [clientQuery.data, initialData, userLocked, selfUserId, userName]);
|
||||
|
||||
return (
|
||||
<BentoGrid cols={2}>
|
||||
@@ -181,6 +190,7 @@ function StepGeneral({ form, errors, set, t, initialData }: StepContentProps) {
|
||||
options={clientOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
error={errors.client_id}
|
||||
disabled={userLocked}
|
||||
loading={clientQuery.isLoading}
|
||||
isLoadingMore={clientQuery.isFetchingNextPage}
|
||||
hasNextPage={!!clientQuery.hasNextPage}
|
||||
@@ -486,6 +496,8 @@ export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
const updateMutation = useUpdateIntlPayment(initialData?.id ?? "");
|
||||
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||
|
||||
const { locked: userLocked, userId: selfUserId, userName } = useWebSelfLock(true);
|
||||
|
||||
const {
|
||||
watch,
|
||||
setValue,
|
||||
@@ -494,7 +506,13 @@ export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
clearErrors,
|
||||
setError,
|
||||
} = useForm<IntlPaymentFormData>({
|
||||
defaultValues: initialData ? { ...DEFAULT_FORM_VALUES, ...mapInitial(initialData) } : DEFAULT_FORM_VALUES,
|
||||
defaultValues: initialData
|
||||
? {
|
||||
...DEFAULT_FORM_VALUES,
|
||||
...mapInitial(initialData),
|
||||
...(userLocked ? { client_id: selfUserId } : {}),
|
||||
}
|
||||
: { ...DEFAULT_FORM_VALUES, client_id: selfUserId },
|
||||
});
|
||||
|
||||
const form = watch();
|
||||
@@ -531,7 +549,10 @@ export function IntlPaymentForm({ mode, initialData }: IntlPaymentFormProps) {
|
||||
return { ...fromRHF, ...allSubmittedErrors };
|
||||
}, [rhfErrors, allSubmittedErrors]);
|
||||
|
||||
const stepProps = useMemo(() => ({ form, errors, set, t, mode, initialData }), [form, errors, set, t, mode, initialData]);
|
||||
const stepProps = useMemo(
|
||||
() => ({ form, errors, set, t, mode, initialData, userLocked, selfUserId, userName }),
|
||||
[form, errors, set, t, mode, initialData, userLocked, selfUserId, userName],
|
||||
);
|
||||
|
||||
// ── Navigation ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user