diff --git a/src/frontend/src/components/NERAutocomplete.tsx b/src/frontend/src/components/NERAutocomplete.tsx index 98bab5a619..b77b45470c 100644 --- a/src/frontend/src/components/NERAutocomplete.tsx +++ b/src/frontend/src/components/NERAutocomplete.tsx @@ -28,6 +28,8 @@ interface NERAutocompleteProps { errorMessage?: FieldError; required?: boolean; disabled?: boolean; + noOptionsText?: React.ReactNode; + onInputChange?: (event: React.SyntheticEvent, value: string) => void; } const NERAutocomplete: React.FC = ({ @@ -42,7 +44,9 @@ const NERAutocomplete: React.FC = ({ filterSelectedOptions, errorMessage, required = true, - disabled = false + disabled = false, + noOptionsText, + onInputChange }) => { const theme = useTheme(); @@ -78,6 +82,8 @@ const NERAutocomplete: React.FC = ({ disablePortal id={id} onChange={onChange} + onInputChange={onInputChange} + noOptionsText={noOptionsText} options={options} sx={autocompleteStyle} disabled={disabled} diff --git a/src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementFormView.tsx b/src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementFormView.tsx index c5cea8b05c..f37e638f26 100644 --- a/src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementFormView.tsx +++ b/src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementFormView.tsx @@ -120,7 +120,6 @@ const ReimbursementRequestFormView: React.FC const [datePickerOpen, setDatePickerOpen] = useState(false); const [showAddRefundSourceModal, setShowAddRefundSourceModal] = useState(false); const [newVendorName, setNewVendorName] = useState(''); - const [showCreateVendorField, setShowCreateVendorField] = useState(false); const { mutateAsync: createVendor } = useCreateVendor(); const user = useCurrentUser(); @@ -342,69 +341,47 @@ const ReimbursementRequestFormView: React.FC const mappedVendors = allVendors .sort((a, b) => a.name.localeCompare(b.name)) .map(vendorsToAutocomplete); + + const handleCreateVendor = async () => { + const name = newVendorName.trim(); + if (!name) return; + try { + const created = await createVendor({ name }); + setValue('vendorId', created.vendorId); + onChange(created.vendorId); + toast.success(`Vendor '${created.name}' created.`); + } catch (err: any) { + toast.error(err.message || 'Failed to create vendor'); + } + }; + return ( - - - - v.id === value) || null} - onChange={(_, newValue) => { - if (newValue) { - onChange(newValue.id); - } - }} - size="small" - placeholder="Select Existing Vendor" - errorMessage={errors.vendorId} - /> - - - OR - - - - {showCreateVendorField && ( - - setNewVendorName(e.target.value)} - placeholder="New Vendor Name" - variant="outlined" - size="small" - fullWidth - /> + v.id === value) || null} + onChange={(_, newValue) => { + onChange(newValue ? newValue.id : ''); + }} + onInputChange={(_, inputValue) => setNewVendorName(inputValue)} + noOptionsText={ + newVendorName.trim() ? ( - - )} - + ) : ( + 'No options' + ) + } + size="small" + placeholder="Select Vendor" + errorMessage={errors.vendorId} + /> ); }} />