diff --git a/src/features/view/SubscriptionDetails.tsx b/src/features/view/SubscriptionDetails.tsx index d05c547..e36ad2f 100644 --- a/src/features/view/SubscriptionDetails.tsx +++ b/src/features/view/SubscriptionDetails.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; import { useMutation, useQuery } from '@tanstack/react-query'; import { SectionTitle, sectionFrame } from '../../components/SectionTitle'; import DOMPurify from 'dompurify'; -import { Box, Button, Checkbox, FormControlLabel, MenuItem, Paper, Stack, TextField, Typography } from '@mui/material'; +import { Autocomplete, Box, Button, Checkbox, FormControlLabel, MenuItem, Paper, Stack, TextField, Typography } from '@mui/material'; import { useAuth } from '../../auth/AuthContext'; import { useNotify } from '../../notify/NotifyProvider'; import { useLabel, useT, useUi } from '../../i18n'; @@ -100,11 +100,21 @@ export function SubscriptionDetails({ data, label, id, actions, onChanged }: { d staleTime: 5 * 60_000, }); const autoInvestors = useQuery({ - queryKey: ['sub-investors', autoEstate], - queryFn: () => getOptions('getInvestorsInLocation', { locationId: autoEstate }), + queryKey: ['sub-active-investors', autoEstate], + // the area's investor list does not look at the investor's status, so it is narrowed to the investors the backend still + // lists as registered (deactivated, blocked and deleted ones are not in that list); both lists use the same investor ids + queryFn: async () => { + const [inArea, registered] = await Promise.all([ + getOptions('getInvestorsInLocation', { locationId: autoEstate }), + getOptions('getStakeHoldersList', { STAKEHOLDER_ID: '7', STAKEHOLDER_NAME: 'INVESTORS' }), + ]); + const ok = new Set(registered.map((o) => String(o.CODE))); + return inArea.filter((o) => ok.has(String(o.CODE))); + }, enabled: canEditAuto && autoOn && !!autoEstate, staleTime: 5 * 60_000, }); + const investorOptions = (autoInvestors.data ?? []).map((o) => ({ code: String(o.CODE), label: String(o.NAME || t(o.CAPTION_CODE ?? String(o.CODE))) })); const saveAuto = useMutation({ meta: { loading: 'saving' }, mutationFn: () => { @@ -196,9 +206,18 @@ export function SubscriptionDetails({ data, label, id, actions, onChanged }: { d { setAutoEstate(e.target.value); setAutoInvestor(''); }}> {(estates.data ?? []).map((o) => {o.NAME || t(o.CAPTION_CODE ?? String(o.CODE))})} - setAutoInvestor(e.target.value)}> - {(autoInvestors.data ?? []).map((o) => {o.NAME || t(o.CAPTION_CODE ?? String(o.CODE))})} - + {/* only the investors located in the chosen industrial area (reloaded when it changes), searchable by name */} + o.code === autoInvestor) ?? null} + onChange={(_, o) => setAutoInvestor(o?.code ?? '')} + isOptionEqualToValue={(a, b) => a.code === b.code} + getOptionLabel={(o) => o.label} + loading={autoInvestors.isFetching} + noOptionsText={ui('noResults')} + renderInput={(p) => } + /> )} diff --git a/src/i18n/ui.ts b/src/i18n/ui.ts index d55e260..699313f 100644 --- a/src/i18n/ui.ts +++ b/src/i18n/ui.ts @@ -43,6 +43,7 @@ export const UI = { exitFullscreen: { en: 'Exit full screen', ar: 'شاشة مصغرة' }, copy: { en: 'Copy', ar: 'نسخ' }, copied: { en: 'Copied', ar: 'تم النسخ' }, + investorName: { en: 'Investor', ar: 'المستثمر' }, close: { en: 'Close', ar: 'إغلاق' }, cachingTitle: { en: 'System cache', ar: 'ذاكرة النظام المؤقتة' }, cachingNote: {