/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import { useAPIClient, useCompile, useLocationSearch } 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'; interface BaseConfigurationProps { type: 'amap' | 'google'; } const BaseConfiguration: React.FC = ({ type, children }) => { 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)); disableAction.toggle(); message.success(t('Saved successfully')); }) .catch((err) => { message.success(t('Saved failed')); }); }; return (
{children} {isDisabled ? ( ) : ( )}
); }; const AMapConfiguration = () => { const { t } = useMapTranslation(); return ( ); }; const GoogleMapConfiguration = () => { const { t } = useMapTranslation(); return ( ); }; const components = { amap: AMapConfiguration, google: GoogleMapConfiguration, }; const routeList = MapTypes.map((item) => { return { ...item, component: components[item.value], }; }); export const Configuration = () => { const compile = useCompile(); const searchString = useLocationSearch(); const search = new URLSearchParams(searchString); return ( {routeList.map((tab) => { return ( ); })} ); };