diff --git a/src/components/form/form-component.tsx b/src/components/form/form-component.tsx new file mode 100644 index 0000000..fa00227 --- /dev/null +++ b/src/components/form/form-component.tsx @@ -0,0 +1,138 @@ +import { FormColumn } from '@/types/form' +import { UIDataType } from '@/types/ui-data' +import React from 'react' +import { toast } from 'react-hot-toast' + +import { Input } from '@/components/input' + +export const getFormComponent = (column: FormColumn): React.ReactNode => { + if (!Object.values(UIDataType).includes(column.uidt)) { + return ( +
+ This system does not support {column.uidt}. +
+ ) + } + switch (column.uidt) { + case 'SingleLineText': + return ( + + ) + case 'PhoneNumber': + return ( + + ) + case 'Number': + return ( + + ) + case 'Checkbox': + return ( ++ จำเป็นต้องเลือก +
++ This system currently does not support {column.uidt}. +
+ ) + } +} diff --git a/src/components/form/form-question.tsx b/src/components/form/form-question.tsx index f2222d8..60a0273 100644 --- a/src/components/form/form-question.tsx +++ b/src/components/form/form-question.tsx @@ -1,8 +1,6 @@ import { FormColumn } from '@/types/form' -import { UIDataType } from '@/types/ui-data' -import toast from 'react-hot-toast' -import { Input } from '@/components/input' +import { getFormComponent } from '@/components/form/form-component' export function FormQuestion({ column }: { column: FormColumn }) { return ( @@ -16,114 +14,7 @@ export function FormQuestion({ column }: { column: FormColumn }) { {column.description} - {UIDataType[column.uidt] === UIDataType.SingleLineText ? ( - - ) : null} - {UIDataType[column.uidt] === UIDataType.PhoneNumber ? ( - - ) : null} - {UIDataType[column.uidt] === UIDataType.Number ? ( - - ) : null} - {UIDataType[column.uidt] === UIDataType.Checkbox ? ( -- จำเป็นต้องเลือก -
-