YANG QIA 06f11a2d08
refactor(auth): move auth client from core to the plugin & refactor auth client api (#3215)
* refactor(auth): auth client api

* fix: build

* fix: dependencies

* fix: fix T-2777

* fix: fix T-2776

* chore: update type

* fix: build

* fix: allowSignUp

* fix: file name

* fix: file name

* refactor: client api

* fix: build

* chore: update name

* fix: tsx must be loaded with --import instead of --loader

* fix: type

* fix: type

* fix: type

* fix: type

* fix: bug

* chore: improve wording

* fix: test

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2023-12-21 20:19:25 +08:00

43 lines
1.1 KiB
TypeScript

import React from 'react';
import { observer, useForm } from '@formily/react';
import { useActionContext, usePlugin, useRecord, useRequest } from '@nocobase/client';
import { useEffect } from 'react';
import AuthPlugin from '..';
export const useValuesFromOptions = (options) => {
const record = useRecord();
const result = useRequest(
() =>
Promise.resolve({
data: {
...record.options,
},
}),
{
...options,
manual: true,
},
);
const { run } = result;
const ctx = useActionContext();
useEffect(() => {
if (ctx.visible) {
run();
}
}, [ctx.visible, run]);
return result;
};
export const useAdminSettingsForm = (authType: string) => {
const plugin = usePlugin(AuthPlugin);
const auth = plugin.authTypes.get(authType);
return auth?.components?.AdminSettingsForm;
};
export const Options = observer(() => {
const form = useForm();
const record = useRecord();
const Component = useAdminSettingsForm(form.values.authType || record.authType);
return Component ? <Component /> : null;
});