被雨水过滤的空气-Rairn 6eed9ac2bb
refactor: fix warning of antd 4.x (#1998)
* refactor: fix warning by codemod

* refactor: fix warning of Dropdown

* perf: use memo

* refactor: resolve SchemaInitializer

* refactor: fix lint

* refactor: remove SettingsForm

* refactor: resolve SchemaInitializer

* refactor: fix lint

* refactor: move useMenuItem to root dir

* chore: fix conflicts

* refactor: resolve SchemaSetting

* refactor: fix lint

* test: fix failed

* chore: upgrade Vite

* fix: fix style

* refactor: fix lint

* refactor: extract component

* refactor: resovle Menu

* refactor: resolve Tabs

* refactor(getPopupContainer): should return the unique div

* refactor(Drawer): change style to rootStyle and className to rootClassName

* chore: update yarn.lock

* fix: fix T-432

* fix: fix T-338

* fix: fix T-490

* fix: collection fields

* fix: fix style

* fix: fix T-500

* fix: fix SettingMenu error (close T-516)

* fix: fix tanslation of Map (T-506)

* style: fix style (T-508)

* fix: fix schemaSetting switch of mobile (T-517)

* fix: fix T-518

* fix: fix T-524

* fix: fix T-507

* perf: optimize SchemaInitializer.Button

* perf: optimize SchemaSettings

* fix: fix serch of SchemaInitializer (T-547)

* chore: change delay

* fix: fix button style (T-548)

* fix: fix scroll bar

* fix: update yarn.lock

* fix: fix build error

* fix: should update sideMenu when change it

* fix: fix build error

* chore: mouseEnterDelay

* fix: fix group menu can not selected
2023-06-22 19:51:16 +08:00

94 lines
2.4 KiB
TypeScript

import { useAPIClient, useCompile } from '@nocobase/client';
import { useBoolean } from 'ahooks';
import { Button, Card, Form, Input, Tabs, message } from 'antd';
import React, { useEffect, useMemo } from 'react';
import { MapTypes } from '../constants';
import { MapConfigurationResourceKey, getSSKey, useMapConfiguration } from '../hooks';
import { useMapTranslation } from '../locale';
const AMapConfiguration = ({ type }) => {
const { t } = useMapTranslation();
const [isDisabled, disableAction] = useBoolean(false);
const apiClient = useAPIClient();
const [form] = Form.useForm();
const data = useMapConfiguration(type);
useEffect(() => {
if (data) {
form.setFieldsValue(data);
disableAction.toggle();
}
}, [data]);
const resource = useMemo(() => {
return apiClient.resource(MapConfigurationResourceKey);
}, [apiClient]);
const onSubmit = (values) => {
resource
.set({
...values,
type,
})
.then((res) => {
sessionStorage.removeItem(getSSKey(type));
message.success(t('Saved successfully'));
})
.catch((err) => {
message.success(t('Saved failed'));
});
};
return (
<Form form={form} layout="vertical" onFinish={onSubmit}>
<Form.Item required name="accessKey" label={t('Access key')}>
<Input disabled={isDisabled} />
</Form.Item>
<Form.Item required name="securityJsCode" label={t('securityJsCode or serviceHost')}>
<Input disabled={isDisabled} />
</Form.Item>
{isDisabled ? (
<Button onClick={disableAction.toggle} type="ghost">
{t('Edit')}
</Button>
) : (
<Form.Item>
<Button type="primary" htmlType="submit">
{t('Save')}
</Button>
</Form.Item>
)}
</Form>
);
};
const components = {
amap: AMapConfiguration,
google: () => <div>Coming soon</div>,
};
const tabList = MapTypes.map((item) => {
return {
...item,
component: components[item.value],
};
});
const Configuration = () => {
const compile = useCompile();
return (
<Card bordered>
<Tabs
type="card"
items={tabList.map((tab) => {
return {
key: tab.value,
label: compile(tab.label),
children: <tab.component type={tab.value} />,
};
})}
/>
</Card>
);
};
export default Configuration;