Skip to content

Commit 709ba41

Browse files
committed
chore: refactor to use idea buttons
1 parent f5314f8 commit 709ba41

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

packages/frontend/src/components/AiBuilder/components/AIFormModalContent.tsx

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ import { FormLabel, useIsMobile } from '@opengovsg/design-system-react'
1818
import pairLogo from '@/assets/pair-logo.svg'
1919
import { ImageBox } from '@/components/FlowStepConfigurationModal/ChooseAndAddConnection/ConfigureExcelConnection'
2020

21-
import { AI_FORM_FIELDS, AI_FORM_IDEAS } from '../constants'
21+
import {
22+
AI_FORM_FIELDS,
23+
AI_FORM_IDEAS,
24+
AiChatIdea,
25+
AiFormIdea,
26+
} from '../constants'
2227
import { AI_FORM_SCHEMA, AiFormData } from '../schema'
2328

29+
import IdeaButtons from './IdeaButtons'
30+
2431
export const AIFormModalContent = ({
2532
flowName,
2633
trigger,
@@ -52,9 +59,9 @@ export const AIFormModalContent = ({
5259
},
5360
})
5461

55-
const handleIdeaClick = (idea: (typeof AI_FORM_IDEAS)[number]) => {
56-
setValue('trigger', idea.trigger, { shouldValidate: true })
57-
setValue('actions', idea.actions, { shouldValidate: true })
62+
const handleIdeaClick = (idea: AiChatIdea | AiFormIdea) => {
63+
setValue('trigger', (idea as AiFormIdea).trigger, { shouldValidate: true })
64+
setValue('actions', (idea as AiFormIdea).actions, { shouldValidate: true })
5865
}
5966

6067
return (
@@ -85,44 +92,24 @@ export const AIFormModalContent = ({
8592
)}
8693
</FormControl>
8794
))}
88-
<Flex flexDir="column">
89-
<FormLabel isRequired>
90-
{/* arbitrary isRequired to hide optional text */}
91-
Need inspiration? Try one of these:
92-
</FormLabel>
93-
<Flex
94-
flexDir="row"
95-
gap={2}
96-
justifyContent="space-between"
97-
flexWrap="wrap"
98-
>
99-
{AI_FORM_IDEAS.map((idea) => (
100-
<Button
101-
key={idea.label}
102-
size="xs"
103-
bgColor="interaction.muted.main.active"
104-
color="primary.500"
105-
variant="clear"
106-
_hover={{
107-
bgColor: 'primary.200',
108-
}}
109-
onClick={() => handleIdeaClick(idea)}
110-
w={isMobile ? 'calc(50% - 4px)' : 'auto'}
111-
flexShrink={0}
112-
>
113-
<Text textStyle="caption-1">{idea.label}</Text>
114-
</Button>
115-
))}
116-
</Flex>
117-
</Flex>
95+
{type === 'create' && (
96+
<IdeaButtons
97+
ideas={AI_FORM_IDEAS}
98+
onClick={(idea: AiChatIdea | AiFormIdea) =>
99+
handleIdeaClick(idea)
100+
}
101+
/>
102+
)}
118103
</Flex>
119104
</ModalBody>
120105
<ModalFooter>
121106
<Flex justifyContent="space-between" alignItems="center" w="100%">
122-
<Flex gap={1} alignItems="center">
123-
<Text textStyle="body-1">Powered by </Text>
124-
<ImageBox imageUrl={pairLogo} boxSize={10} />
125-
</Flex>
107+
{!isMobile && (
108+
<Flex gap={1} alignItems="center" justifyContent="center">
109+
<Text textStyle="body-1">Powered by </Text>
110+
<ImageBox imageUrl={pairLogo} boxSize={10} />
111+
</Flex>
112+
)}
126113
<Flex gap={4}>
127114
<Button variant="clear" colorScheme="secondary" onClick={onBack}>
128115
Back

0 commit comments

Comments
 (0)