-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support customizing prompts & greeting (#343)
* feat: support customizing prompts & greeting * remove unnecessary package * fix react build issue * fix: support mobile & ignore empty values
- Loading branch information
Showing
17 changed files
with
192 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, { useState } from 'react'; | ||
import { Modal, Form, Input, Button, FloatButton, ConfigProvider, theme } from 'antd'; | ||
import { SettingOutlined } from '@ant-design/icons'; | ||
import { useAppDispatch, useAppSelector } from '@/common'; | ||
import { setAgentSettings } from '@/store/reducers/global'; | ||
|
||
interface FormValues { | ||
greeting: string; | ||
prompt: string; | ||
} | ||
|
||
const FormModal: React.FC = () => { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
const [form] = Form.useForm<FormValues>(); | ||
const dispatch = useAppDispatch(); | ||
const agentSettings = useAppSelector(state => state.global.agentSettings); | ||
|
||
const showModal = () => { | ||
form.setFieldsValue(agentSettings); | ||
setIsModalVisible(true); | ||
}; | ||
|
||
const handleOk = async () => { | ||
try { | ||
const values = await form.validateFields(); | ||
console.log('Form Values:', values); | ||
// Handle the form submission logic here | ||
dispatch(setAgentSettings(values)); | ||
setIsModalVisible(false); | ||
form.resetFields(); | ||
} catch (errorInfo) { | ||
console.log('Validate Failed:', errorInfo); | ||
} | ||
}; | ||
|
||
const handleCancel = () => { | ||
setIsModalVisible(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ConfigProvider | ||
theme={ | ||
{ | ||
algorithm: theme.darkAlgorithm, | ||
components: { | ||
Modal: { | ||
contentBg: "#272A2F", | ||
headerBg: "#272A2F", | ||
footerBg: "#272A2F", | ||
} | ||
} | ||
} | ||
}> | ||
<FloatButton type="primary" icon={<SettingOutlined></SettingOutlined>} onClick={showModal}> | ||
</FloatButton> | ||
<Modal | ||
title="Settings" | ||
visible={isModalVisible} | ||
onOk={handleOk} | ||
onCancel={handleCancel} | ||
okText="OK" | ||
cancelText="Cancel" | ||
> | ||
<Form | ||
form={form} | ||
layout="vertical" | ||
name="form_in_modal" | ||
> | ||
<Form.Item | ||
name="greeting" | ||
label="Greeting" | ||
> | ||
<Input.TextArea rows={2} placeholder="Enter the greeting, leave it blank if you want to use default one." /> | ||
</Form.Item> | ||
|
||
<Form.Item | ||
name="prompt" | ||
label="Prompt" | ||
> | ||
<Input.TextArea rows={4} placeholder="Enter the prompt, leave it blank if you want to use default one." /> | ||
</Form.Item> | ||
</Form> | ||
</Modal> | ||
</ConfigProvider> | ||
</> | ||
); | ||
}; | ||
|
||
export default FormModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.