refactor: fixes to custom field

This commit is contained in:
Carlos Valente
2025-07-11 16:49:41 +02:00
parent 4d419c0877
commit d8c1c38123
20 changed files with 103 additions and 108 deletions
@@ -7,8 +7,8 @@ import { getURLSearchParamsFromObj, makeOptionsFromCustomFields } from '../viewP
describe('makeOptionsFromCustomFields()', () => {
const testCustomFields: CustomFields = {
field1: { label: 'Field 1', colour: 'red', type: 'string' },
field2: { label: 'Field 2', colour: 'blue', type: 'string' },
field1: { label: 'Field 1', colour: 'red', type: 'text' },
field2: { label: 'Field 2', colour: 'blue', type: 'text' },
};
it('creates an array of options to use in a select', () => {
@@ -16,7 +16,7 @@ interface CustomFieldEntryProps {
colour: string;
label: string;
fieldKey: string;
type: 'string' | 'image';
type: CustomField['type'];
onEdit: (key: CustomFieldKey, patch: CustomField) => Promise<void>;
onDelete: (key: CustomFieldKey) => Promise<void>;
}
@@ -42,7 +42,7 @@ export default function CustomFieldForm(props: CustomFieldsFormProps) {
watch,
formState: { errors, isSubmitting, isValid, isDirty },
} = useForm<CustomFieldFormData>({
defaultValues: { type: 'string', label: initialLabel || '', colour: initialColour || '' },
defaultValues: { type: 'text', label: initialLabel || '', colour: initialColour || '' },
resetOptions: {
keepDirtyValues: true,
},
@@ -96,7 +96,7 @@ export default function CustomFieldForm(props: CustomFieldsFormProps) {
onValueChange={(value) => setValue('type', value, { shouldDirty: true })}
value={watch('type')}
items={[
{ value: 'string', label: 'Text' },
{ value: 'text', label: 'Text' },
{ value: 'image', label: 'Image' },
]}
/>
@@ -30,7 +30,7 @@ export default function EntryEditorCustomFields({
const { backgroundColor, color } = getAccessibleColour(customFields[fieldKey].colour);
const labelText = customFields[fieldKey].label;
if (customFields[fieldKey].type === 'string') {
if (customFields[fieldKey].type === 'text') {
return (
<EventTextArea
key={key}
@@ -183,7 +183,7 @@ export function makeCuesheetColumns(customFields: CustomFields): ColumnDef<Ontim
id: key,
header: customFields[key].label,
meta: { colour: customFields[key].colour, type: customFields[key].type },
cell: customFields[key].type === 'string' ? MakeCustomField : LazyImage,
cell: customFields[key].type === 'text' ? MakeCustomField : LazyImage,
size: 250,
minSize: 75,
}));