2022-12-16 15:00:01 +01:00
|
|
|
import { Select } from '@mantine/core';
|
2022-08-27 15:58:36 +02:00
|
|
|
import { useEffect } from 'react';
|
2022-10-27 14:22:15 +02:00
|
|
|
import { ISelect } from '../../../../interfaces/dialog';
|
2022-05-03 15:08:28 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
2022-08-09 23:50:14 +02:00
|
|
|
row: ISelect;
|
2022-05-03 15:08:28 +02:00
|
|
|
index: number;
|
2022-08-09 23:50:14 +02:00
|
|
|
handleChange: (value: string, index: number) => void;
|
2022-05-03 15:08:28 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-16 15:00:01 +01:00
|
|
|
// TODO: set label to value of value when there is no label provided
|
2022-05-03 15:08:28 +02:00
|
|
|
const SelectField: React.FC<Props> = (props) => {
|
2022-08-05 15:10:37 +02:00
|
|
|
useEffect(() => {
|
2022-08-27 15:58:36 +02:00
|
|
|
if (props.row.default) {
|
2022-08-05 15:10:37 +02:00
|
|
|
props.row.options?.map((option) => {
|
2022-08-27 15:58:36 +02:00
|
|
|
if (props.row.default === option.value) {
|
2022-08-05 15:10:37 +02:00
|
|
|
props.handleChange(option.value, props.index);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
2022-05-03 15:08:28 +02:00
|
|
|
return (
|
2022-12-16 15:00:01 +01:00
|
|
|
<Select
|
|
|
|
|
onChange={(value) => props.handleChange(value as string, props.index)}
|
|
|
|
|
defaultValue={props.row.default || ''}
|
|
|
|
|
disabled={props.row.disabled}
|
|
|
|
|
data={props.row.options}
|
|
|
|
|
label={props.row.label}
|
|
|
|
|
description={props.row.description}
|
|
|
|
|
/>
|
2022-05-03 15:08:28 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SelectField;
|