From 6cc678947b4974638851113b706ac05c8875a9a1 Mon Sep 17 00:00:00 2001 From: Kevin Foong <55353265+kevin9foong@users.noreply.github.com> Date: Fri, 29 Nov 2024 23:11:09 +0800 Subject: [PATCH 01/22] feat: implement search functionality --- .../FieldListDrawer/FieldListDrawer.tsx | 25 ++++++++++++++++++- .../field-panels/BasicFieldPanel.tsx | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx index 447887f94a..726ab65361 100644 --- a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx @@ -1,9 +1,14 @@ import { useState } from 'react' import { useTranslation } from 'react-i18next' +import { BiSearch } from 'react-icons/bi' import { Box, Divider, Flex, + Icon, + Input, + InputGroup, + InputLeftElement, TabList, TabPanel, TabPanels, @@ -24,7 +29,25 @@ import { MyInfoFieldPanel, PaymentsInputPanel, } from './field-panels' -import { FieldSearchBar } from './FieldSearchBar' + +const FieldSearchBar = ({ + searchValue, + onChange, +}: { + searchValue: string + onChange: (e: React.ChangeEvent) => void +}) => ( + + + + + + +) export const FieldListDrawer = (): JSX.Element => { const { t } = useTranslation() diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/field-panels/BasicFieldPanel.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/field-panels/BasicFieldPanel.tsx index a4ee0087c5..8251eef3f2 100644 --- a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/field-panels/BasicFieldPanel.tsx +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/field-panels/BasicFieldPanel.tsx @@ -1,3 +1,4 @@ +import { useMemo } from 'react' import { Box } from '@chakra-ui/react' import { Droppable } from '@hello-pangea/dnd' From 768f9df317b12b4c4ab8fc9a1487542bbc97fa55 Mon Sep 17 00:00:00 2001 From: Kevin Foong <55353265+kevin9foong@users.noreply.github.com> Date: Fri, 29 Nov 2024 23:34:12 +0800 Subject: [PATCH 02/22] feat: add mfb button beside search bar --- .../FieldListDrawer/FieldListDrawer.tsx | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx index 726ab65361..6fd712074d 100644 --- a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx @@ -1,8 +1,9 @@ import { useState } from 'react' import { useTranslation } from 'react-i18next' -import { BiSearch } from 'react-icons/bi' +import { BiSearch, BiSolidMagicWand } from 'react-icons/bi' import { Box, + Button, Divider, Flex, Icon, @@ -14,6 +15,7 @@ import { TabPanels, Tabs, Text, + Tooltip, } from '@chakra-ui/react' import { Tab } from '~components/Tabs' @@ -30,6 +32,22 @@ import { PaymentsInputPanel, } from './field-panels' +const MagicFormBuilderButton = ({ ...styleProps }) => ( + + + +) + const FieldSearchBar = ({ searchValue, onChange, @@ -37,16 +55,19 @@ const FieldSearchBar = ({ searchValue: string onChange: (e: React.ChangeEvent) => void }) => ( - - - - - - + <> + + + + + + + + ) export const FieldListDrawer = (): JSX.Element => { From 8a68323c7c5ae1892771ad3b46ae3363417688ad Mon Sep 17 00:00:00 2001 From: Kevin Foong <55353265+kevin9foong@users.noreply.github.com> Date: Fri, 29 Nov 2024 23:43:49 +0800 Subject: [PATCH 03/22] fix: disable support for mfb for mobile --- .../FieldListDrawer/FieldListDrawer.tsx | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx index 6fd712074d..894c1fc4b6 100644 --- a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx @@ -18,6 +18,7 @@ import { Tooltip, } from '@chakra-ui/react' +import { useIsMobile } from '~hooks/useIsMobile' import { Tab } from '~components/Tabs' import { useCreatePageSidebar } from '~features/admin-form/create/common/CreatePageSidebarContext' @@ -32,21 +33,24 @@ import { PaymentsInputPanel, } from './field-panels' -const MagicFormBuilderButton = ({ ...styleProps }) => ( - - - -) +const MagicFormBuilderButton = ({ ...styleProps }) => { + const isMobile = useIsMobile() + return !isMobile ? ( + + + + ) : null +} const FieldSearchBar = ({ searchValue, From d65f8384c7bcef089619860c94e063d932ec23f5 Mon Sep 17 00:00:00 2001 From: Kevin Foong <55353265+kevin9foong@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:31:14 +0800 Subject: [PATCH 04/22] feat: popover modal for input --- .../FieldListDrawer/FieldListDrawer.tsx | 58 +++----- .../MagicFormBuilderContainer.tsx | 133 ++++++++++++++++++ 2 files changed, 153 insertions(+), 38 deletions(-) create mode 100644 frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/MagicFormBuilderContainer.tsx diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx index 894c1fc4b6..ac2fb4766a 100644 --- a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/FieldListDrawer.tsx @@ -1,9 +1,8 @@ import { useState } from 'react' import { useTranslation } from 'react-i18next' -import { BiSearch, BiSolidMagicWand } from 'react-icons/bi' +import { BiSearch } from 'react-icons/bi' import { Box, - Button, Divider, Flex, Icon, @@ -15,10 +14,8 @@ import { TabPanels, Tabs, Text, - Tooltip, } from '@chakra-ui/react' -import { useIsMobile } from '~hooks/useIsMobile' import { Tab } from '~components/Tabs' import { useCreatePageSidebar } from '~features/admin-form/create/common/CreatePageSidebarContext' @@ -32,25 +29,7 @@ import { MyInfoFieldPanel, PaymentsInputPanel, } from './field-panels' - -const MagicFormBuilderButton = ({ ...styleProps }) => { - const isMobile = useIsMobile() - return !isMobile ? ( - - - - ) : null -} +import { MagicFormBuilderContainer } from './MagicFormBuilderContainer' const FieldSearchBar = ({ searchValue, @@ -58,21 +37,24 @@ const FieldSearchBar = ({ }: { searchValue: string onChange: (e: React.ChangeEvent) => void -}) => ( - <> - - - - - - - - -) +}) => { + return ( + <> + + + + + + + + + ) +} export const FieldListDrawer = (): JSX.Element => { const { t } = useTranslation() diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/MagicFormBuilderContainer.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/MagicFormBuilderContainer.tsx new file mode 100644 index 0000000000..fb306cbca2 --- /dev/null +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/MagicFormBuilderContainer.tsx @@ -0,0 +1,133 @@ +import { useState } from 'react' +import { useForm } from 'react-hook-form' +import { BiSolidMagicWand } from 'react-icons/bi' +import { HiSparkles } from 'react-icons/hi2' +import { + Button, + Flex, + FormControl, + Icon, + Popover, + PopoverAnchor, + PopoverBody, + PopoverCloseButton, + PopoverContent, + PopoverFooter, + PopoverHeader, + Portal, + Text, + Textarea, + Tooltip, +} from '@chakra-ui/react' + +import { useIsMobile } from '~hooks/useIsMobile' +import { FormErrorMessage } from '~components/FormControl/FormErrorMessage/FormErrorMessage' + +import { useAssistanceMutations } from '~features/admin-form/assistance/mutations' + +const GENERATE_FORM_PLACEHOLDER = + 'Describe form, fields and sections to create...' + +export const MagicFormBuilderContainer = () => { + const isMobile = useIsMobile() + const [isOpen, setIsOpen] = useState(false) + + return !isMobile ? ( + <> + + + ) : null +} + +const MagicFormBuilderButton = ({ + onClick, + ...styleProps +}: { onClick: () => void } & React.ComponentProps) => { + return ( + + + + ) +} + +interface TextPromptInputs { + prompt: string +} + +const MagicFormBuilderPopover = ({ + isOpen, + setIsOpen, +}: { + isOpen: boolean + setIsOpen: (isOpen: boolean) => void +}) => { + const { + register, + handleSubmit, + formState: { errors }, + } = useForm() + + const { useMakeTextPromptMutation } = useAssistanceMutations() + + const onSubmit = async ({ prompt }: TextPromptInputs) => { + useMakeTextPromptMutation.mutate(prompt, { + onSettled: () => setIsOpen(false), + }) + } + + return ( + + + setIsOpen(!isOpen)} /> + + + {/* TODO: (MFBv1.1) Fix the position of the popover. */} + +
+ + Generate form + + setIsOpen(false)} /> + + +