Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](base/setting): ee processConnection request api error #188

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,382 @@
import { useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
Form,
Radio,
RadioGroupProps,
Space,
Spin,
Typography,
message as messageApi
} from 'antd';
import { useBoolean, useRequest } from 'ahooks';
import { BasicButton, BasicInput, EmptyBox } from '@actiontech/shared';
import {
CustomLabelContent,
FormItemLabel,
FormItemNoLabel
} from '@actiontech/shared/lib/components/FormCom';
import useConfigRender, {
ReadOnlyConfigColumnsType
} from '../../hooks/useConfigRender';
import useConfigSwitch from '../../hooks/useConfigSwitch';
import ConfigTestBtn from '../../components/ConfigTestBtn';
import ConfigTestPopoverForm from '../../components/ConfigTestPopoverForm';
import ConfigModifyBtn from '../../components/ConfigModifyBtn';
import ConfigSwitch from '../../components/ConfigSwitch';
import { ResponseCode } from '@actiontech/shared/lib/enum';
import { FormFields, TestFormFields } from './index.type';
import { TestFeishuConfigurationReqV1AccountTypeEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';
import { defaultFormData, switchFieldName } from './index.data';
import configuration from '@actiontech/shared/lib/api/sqle/service/configuration';
import { IFeishuConfigurationV1 } from '@actiontech/shared/lib/api/sqle/service/common';
import { formItemLayout } from '@actiontech/shared/lib/components/FormCom/style';
import { phoneRule } from '@actiontech/shared/lib/utils/FormRule';

const LarkAuditSettingEEIndex = () => {
const { t } = useTranslation();

Check warning on line 37 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const [message, messageContextHolder] = messageApi.useMessage();

Check warning on line 38 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const {
form,
renderConfigForm,
startModify,
modifyFinish,
modifyFlag,
extraButtonsVisible,
enabled
} = useConfigRender<FormFields>({
switchFieldName,
switchFieldLabel: (
<CustomLabelContent
title={t('dmsSystem.larkAudit.enable')}
tips={t('dmsSystem.larkAudit.titleTips')}
/>
)
});

Check warning on line 55 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const [submitLoading, { setTrue: startSubmit, setFalse: submitFinish }] =
useBoolean();

Check warning on line 58 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const {
data: larkAuditInfo,
loading: getLarkAuditInfoLoading,
refresh: refreshLarkAuditInfo
} = useRequest(
() =>
configuration
.getFeishuAuditConfigurationV1()
.then((res) => res.data.data ?? {}),

Check warning on line 68 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 68 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
{
onSuccess(res) {
if (res) {
form.setFieldsValue({
enabled: !!res.is_feishu_notification_enabled
});

Check warning on line 74 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 75 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
}
);

Check warning on line 78 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const isConfigClosed = useMemo(() => {
return !larkAuditInfo?.is_feishu_notification_enabled;

Check warning on line 81 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}, [larkAuditInfo]);

Check warning on line 82 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const setFormDefaultValue = useCallback(() => {
form.setFieldsValue({
appKey: larkAuditInfo?.app_id,
appSecret: undefined
});

Check warning on line 88 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}, [form, larkAuditInfo]);

Check warning on line 89 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const handleClickModify = () => {
setFormDefaultValue();

Check warning on line 92 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
startModify();

Check warning on line 93 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 94 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const handleClickCancel = () => {
if (isConfigClosed) form.setFieldValue(switchFieldName, false);

Check warning on line 97 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 97 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
setFormDefaultValue();

Check warning on line 98 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
modifyFinish();

Check warning on line 99 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 100 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const handleToggleSwitch = (open: boolean) => {
form.setFieldValue(switchFieldName, open);

Check warning on line 103 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 104 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const submitLarkAuditConfig = (values: FormFields) => {
startSubmit();

Check warning on line 107 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
configuration
.updateFeishuAuditConfigurationV1({
is_feishu_notification_enabled: values.enabled,
app_id: values.appKey,
app_secret: values.appSecret
})
.then((res) => {
if (res.data.code === ResponseCode.SUCCESS) {
handleClickCancel();

Check warning on line 116 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
refreshLarkAuditInfo();

Check warning on line 117 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 118 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
})
.finally(() => {
submitFinish();

Check warning on line 121 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
});

Check warning on line 122 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 123 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const switchOpen = Form.useWatch(switchFieldName, form);

Check warning on line 125 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const {
configSwitchPopoverVisible,
onConfigSwitchPopoverOpen,
onConfigSwitchPopoverConfirm,
onConfigSwitchChange
} = useConfigSwitch({
isConfigClosed,
switchOpen,
modifyFlag,
startSubmit,
submitFinish,
handleClickModify,
handleUpdateConfig: () =>
configuration.updateFeishuAuditConfigurationV1({
...defaultFormData,
is_feishu_notification_enabled: false
}),

Check warning on line 143 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
handleClickCancel,
refreshConfig: refreshLarkAuditInfo,
handleToggleSwitch
});

Check warning on line 147 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const [testForm] = Form.useForm<TestFormFields>();

Check warning on line 149 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const [testPopoverVisible, toggleTestPopoverVisible] = useState(false);

Check warning on line 150 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const [receiveType, setReceiveType] =
useState<TestFeishuConfigurationReqV1AccountTypeEnum>(
TestFeishuConfigurationReqV1AccountTypeEnum.email
);

Check warning on line 154 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const testing = useRef(false);

Check warning on line 155 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const testLarkAuditConfiguration = async () => {
if (testing.current) {
return;

Check warning on line 158 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 159 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
testing.current = true;

Check warning on line 160 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
toggleTestPopoverVisible(false);

Check warning on line 161 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const hide = message.loading(t('dmsSystem.larkAudit.testing'), 0);

Check warning on line 162 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const values = await testForm.validateFields();

Check warning on line 163 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

configuration
.testFeishuAuditConfigV1({
account:
receiveType === TestFeishuConfigurationReqV1AccountTypeEnum.email
? values.receiveEmail
: values.receivePhone,
account_type: values.receiveType
})
.then((res) => {
if (res.data.code === ResponseCode.SUCCESS) {
const resData = res.data?.data;

if (resData?.is_message_sent_normally) {
message.success(t('dmsSystem.larkAudit.testSuccess'));
} else {
message.error(resData?.error_message ?? t('common.unknownError'));
}
}

Check warning on line 182 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
})
.finally(() => {
hide();
testing.current = false;
testForm.resetFields();
setReceiveType(TestFeishuConfigurationReqV1AccountTypeEnum.email);
});

Check warning on line 189 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 190 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const handleChangeReceiveType: RadioGroupProps['onChange'] = (e) => {
const receiveType = e.target.value;
setReceiveType(receiveType);

if (receiveType === TestFeishuConfigurationReqV1AccountTypeEnum.email) {
testForm.resetFields(['receivePhone']);
} else {
testForm.resetFields(['receiveEmail']);
}
};
const onTestPopoverOpen = (open: boolean) => {
if (!enabled) {
return;
}
if (!open) {
testForm.resetFields();
setReceiveType(TestFeishuConfigurationReqV1AccountTypeEnum.email);
}
toggleTestPopoverVisible(open);
};

const readonlyColumnsConfig: ReadOnlyConfigColumnsType<IFeishuConfigurationV1> =
useMemo(() => {
return [
{
label: 'App ID',
span: 3,
dataIndex: 'app_id',
hidden: !larkAuditInfo?.is_feishu_notification_enabled,
render: (val) => (
<Typography.Paragraph>{val || '--'}</Typography.Paragraph>
)
}
];
}, [larkAuditInfo]);
return (
<Spin spinning={getLarkAuditInfoLoading || submitLoading}>
{messageContextHolder}
{renderConfigForm({
data: larkAuditInfo ?? {},
columns: readonlyColumnsConfig,
configExtraButtons: (
<Space size={12} hidden={isConfigClosed || !extraButtonsVisible}>
<ConfigTestBtn
testingRef={testing}
popoverOpen={testPopoverVisible}
onPopoverOpenChange={onTestPopoverOpen}
popoverForm={
<ConfigTestPopoverForm
handleTest={testLarkAuditConfiguration}
handleCancel={() => toggleTestPopoverVisible(false)}
>
<Form
form={testForm}
colon={false}
{...formItemLayout.fullLine}
>
<FormItemLabel
name="receiveType"
label={t('dmsSystem.larkAudit.receiveType')}
initialValue={
TestFeishuConfigurationReqV1AccountTypeEnum.email
}
style={{ marginBottom: 0 }}
>
<Radio.Group
size="small"
onChange={handleChangeReceiveType}
>
<Radio.Button
value={
TestFeishuConfigurationReqV1AccountTypeEnum.email
}
>
{t('dmsSystem.larkAudit.email')}
</Radio.Button>
<Radio.Button
value={
TestFeishuConfigurationReqV1AccountTypeEnum.phone
}
>
{t('dmsSystem.larkAudit.phone')}
</Radio.Button>
</Radio.Group>
</FormItemLabel>
<EmptyBox
if={
receiveType ===
TestFeishuConfigurationReqV1AccountTypeEnum.phone
}
defaultNode={
<FormItemNoLabel
style={{ marginBottom: 0 }}
name="receiveEmail"
label={t('dmsSystem.larkAudit.email')}
rules={[
{
required: true
},
{
type: 'email'
}
]}
>
<BasicInput />
</FormItemNoLabel>
}
>
<FormItemNoLabel
style={{ marginBottom: 0 }}
name="receivePhone"
label={t('dmsSystem.larkAudit.phone')}
rules={[
{
required: true
},
...phoneRule()
]}
>
<BasicInput />
</FormItemNoLabel>
</EmptyBox>
</Form>
</ConfigTestPopoverForm>
}
/>
<ConfigModifyBtn onClick={handleClickModify} />
</Space>
),
configSwitchNode: (
<ConfigSwitch
switchFieldName={switchFieldName}
switchOpen={switchOpen}
modifyFlag={modifyFlag}
submitLoading={submitLoading}
popoverVisible={configSwitchPopoverVisible}
onConfirm={onConfigSwitchPopoverConfirm}
onSwitchChange={onConfigSwitchChange}
onSwitchPopoverOpen={onConfigSwitchPopoverOpen}
/>
),
configField: (
<>
<FormItemLabel
className="has-required-style"
label="App ID"
name="appKey"
rules={[{ required: true }]}
>
<BasicInput
placeholder={t('common.form.placeholder.input', {
name: 'App Key'
})}
/>
</FormItemLabel>
<FormItemLabel
className="has-required-style"
label="App Secret"
name="appSecret"
rules={[{ required: true }]}
>
<BasicInput.Password
placeholder={t('common.form.placeholder.input', {
name: 'App Secret'
})}
/>
</FormItemLabel>
</>
),
submitButtonField: (
<FormItemNoLabel label=" " colon={false}>
<Space size={12}>
<BasicButton onClick={handleClickCancel} disabled={submitLoading}>
{t('common.cancel')}
</BasicButton>
<BasicButton
htmlType="submit"
type="primary"
disabled={submitLoading}
>
{t('common.submit')}
</BasicButton>
</Space>
</FormItemNoLabel>
),
submit: submitLarkAuditConfig
})}
</Spin>
);
};

Check warning on line 380 in packages/base/src/page/System/ProcessConnection/LarkAuditSetting/index.ee.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

export default LarkAuditSettingEEIndex;
Loading
Loading