|
| 1 | +import React from 'react'; |
| 2 | +import { Flex, Box, Button, ModalBody, Input, Link } from '@chakra-ui/react'; |
| 3 | +import MyModal from '@fastgpt/web/components/common/MyModal'; |
| 4 | +import { PublishChannelEnum } from '@fastgpt/global/support/outLink/constant'; |
| 5 | +import type { WecomAppType, OutLinkEditType } from '@fastgpt/global/support/outLink/type'; |
| 6 | +import { useTranslation } from 'next-i18next'; |
| 7 | +import { useForm } from 'react-hook-form'; |
| 8 | +import { createShareChat, updateShareChat } from '@/web/support/outLink/api'; |
| 9 | +import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; |
| 10 | +import BasicInfo from '../components/BasicInfo'; |
| 11 | +import { getDocPath } from '@/web/common/system/doc'; |
| 12 | +import { useSystemStore } from '@/web/common/system/useSystemStore'; |
| 13 | +import MyIcon from '@fastgpt/web/components/common/Icon'; |
| 14 | +import { useSystem } from '@fastgpt/web/hooks/useSystem'; |
| 15 | +import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; |
| 16 | + |
| 17 | +const WecomEditModal = ({ |
| 18 | + appId, |
| 19 | + defaultData, |
| 20 | + onClose, |
| 21 | + onCreate, |
| 22 | + onEdit, |
| 23 | + isEdit = false |
| 24 | +}: { |
| 25 | + appId: string; |
| 26 | + defaultData: OutLinkEditType<WecomAppType>; |
| 27 | + onClose: () => void; |
| 28 | + onCreate: (id: string) => void; |
| 29 | + onEdit: () => void; |
| 30 | + isEdit?: boolean; |
| 31 | +}) => { |
| 32 | + const { t } = useTranslation(); |
| 33 | + const { |
| 34 | + register, |
| 35 | + setValue, |
| 36 | + handleSubmit: submitShareChat |
| 37 | + } = useForm({ |
| 38 | + defaultValues: defaultData |
| 39 | + }); |
| 40 | + |
| 41 | + const { runAsync: onclickCreate, loading: creating } = useRequest2( |
| 42 | + (e) => |
| 43 | + createShareChat({ |
| 44 | + ...e, |
| 45 | + appId, |
| 46 | + type: PublishChannelEnum.wecom |
| 47 | + }), |
| 48 | + { |
| 49 | + errorToast: t('common:common.Create Failed'), |
| 50 | + successToast: t('common:common.Create Success'), |
| 51 | + onSuccess: onCreate |
| 52 | + } |
| 53 | + ); |
| 54 | + |
| 55 | + const { runAsync: onclickUpdate, loading: updating } = useRequest2((e) => updateShareChat(e), { |
| 56 | + errorToast: t('common:common.Update Failed'), |
| 57 | + successToast: t('common:common.Update Success'), |
| 58 | + onSuccess: onEdit |
| 59 | + }); |
| 60 | + |
| 61 | + const { feConfigs } = useSystemStore(); |
| 62 | + |
| 63 | + return ( |
| 64 | + <MyModal |
| 65 | + iconSrc="/imgs/modal/shareFill.svg" |
| 66 | + title={isEdit ? t('publish:wecom.edit_modal_title') : t('publish:wecom.create_modal_title')} |
| 67 | + minW={['auto', '60rem']} |
| 68 | + > |
| 69 | + <ModalBody display={'grid'} gridTemplateColumns={['1fr', '1fr 1fr']} fontSize={'14px'} p={0}> |
| 70 | + <Box p={8} minH={['auto', '400px']} borderRight={'base'}> |
| 71 | + <BasicInfo register={register} setValue={setValue} defaultData={defaultData} /> |
| 72 | + </Box> |
| 73 | + <Flex p={8} minH={['auto', '400px']} flexDirection="column" gap={6}> |
| 74 | + <Flex alignItems="center"> |
| 75 | + <Box color="myGray.600">{t('publish:wecom.api')}</Box> |
| 76 | + {feConfigs?.docUrl && ( |
| 77 | + <Link |
| 78 | + href={feConfigs.openAPIDocUrl || getDocPath('/docs/use-cases/wecom-bot')} |
| 79 | + target={'_blank'} |
| 80 | + ml={2} |
| 81 | + color={'primary.500'} |
| 82 | + fontSize={'sm'} |
| 83 | + > |
| 84 | + <Flex alignItems={'center'}> |
| 85 | + <MyIcon name="book" mr="1" /> |
| 86 | + {t('common:common.Read document')} |
| 87 | + </Flex> |
| 88 | + </Link> |
| 89 | + )} |
| 90 | + </Flex> |
| 91 | + <Flex alignItems={'center'}> |
| 92 | + <FormLabel flex={'0 0 6.25rem'} required> |
| 93 | + Corp ID |
| 94 | + </FormLabel> |
| 95 | + <Input |
| 96 | + placeholder="Corp ID" |
| 97 | + {...register('app.CorpId', { |
| 98 | + required: true |
| 99 | + })} |
| 100 | + /> |
| 101 | + </Flex> |
| 102 | + <Flex alignItems={'center'}> |
| 103 | + <FormLabel flex={'0 0 6.25rem'} required> |
| 104 | + Agent ID |
| 105 | + </FormLabel> |
| 106 | + <Input |
| 107 | + placeholder="Agent ID" |
| 108 | + {...register('app.AgentId', { |
| 109 | + required: true |
| 110 | + })} |
| 111 | + /> |
| 112 | + </Flex> |
| 113 | + <Flex alignItems={'center'}> |
| 114 | + <FormLabel flex={'0 0 6.25rem'} required> |
| 115 | + Secret |
| 116 | + </FormLabel> |
| 117 | + <Input |
| 118 | + placeholder="Secret" |
| 119 | + {...register('app.SuiteSecret', { |
| 120 | + required: true |
| 121 | + })} |
| 122 | + /> |
| 123 | + </Flex> |
| 124 | + <Flex alignItems={'center'}> |
| 125 | + <FormLabel flex={'0 0 6.25rem'} required> |
| 126 | + Token |
| 127 | + </FormLabel> |
| 128 | + <Input |
| 129 | + placeholder="Token" |
| 130 | + {...register('app.CallbackToken', { |
| 131 | + required: true |
| 132 | + })} |
| 133 | + /> |
| 134 | + </Flex> |
| 135 | + <Flex alignItems={'center'}> |
| 136 | + <FormLabel flex={'0 0 6.25rem'} required> |
| 137 | + AES Key |
| 138 | + </FormLabel> |
| 139 | + <Input |
| 140 | + placeholder="AES Key" |
| 141 | + {...register('app.CallbackEncodingAesKey', { |
| 142 | + required: true |
| 143 | + })} |
| 144 | + /> |
| 145 | + </Flex> |
| 146 | + |
| 147 | + <Box flex={1}></Box> |
| 148 | + |
| 149 | + <Flex justifyContent={'end'}> |
| 150 | + <Button variant={'whiteBase'} mr={3} onClick={onClose}> |
| 151 | + {t('common:common.Close')} |
| 152 | + </Button> |
| 153 | + <Button |
| 154 | + isLoading={creating || updating} |
| 155 | + onClick={submitShareChat((data) => |
| 156 | + isEdit ? onclickUpdate(data) : onclickCreate(data) |
| 157 | + )} |
| 158 | + > |
| 159 | + {t('common:common.Confirm')} |
| 160 | + </Button> |
| 161 | + </Flex> |
| 162 | + </Flex> |
| 163 | + </ModalBody> |
| 164 | + </MyModal> |
| 165 | + ); |
| 166 | +}; |
| 167 | + |
| 168 | +export default WecomEditModal; |
0 commit comments