|
|
@@ -8,10 +8,8 @@ import { useSWRxPlugin } from '~/stores/plugin';
|
|
|
|
|
|
import styles from './PluginCard.module.scss';
|
|
|
|
|
|
-
|
|
|
type Props = {
|
|
|
id: string,
|
|
|
- isEnabled: boolean,
|
|
|
name: string,
|
|
|
url: string,
|
|
|
description: string,
|
|
|
@@ -20,30 +18,31 @@ type Props = {
|
|
|
export const PluginCard = (props: Props): JSX.Element => {
|
|
|
|
|
|
const {
|
|
|
- id, isEnabled, name, url, description,
|
|
|
+ id, name, url, description,
|
|
|
} = props;
|
|
|
|
|
|
- const { data } = useSWRxPlugin(id);
|
|
|
+ const { data, mutate } = useSWRxPlugin(id);
|
|
|
|
|
|
if (data == null) {
|
|
|
return <></>;
|
|
|
}
|
|
|
|
|
|
- console.log('first', data.data.isEnabled);
|
|
|
const PluginCardButton = (): JSX.Element => {
|
|
|
const [isEnabled, setState] = useState<boolean>(data.data.isEnabled);
|
|
|
|
|
|
const onChangeHandler = async() => {
|
|
|
- // const { data, mutate } = useSWRxPlugin(id);
|
|
|
-
|
|
|
- console.log('change');
|
|
|
const reqUrl = '/plugins-extension/plugin';
|
|
|
- console.log('id', id);
|
|
|
- const res = await apiv3Post(reqUrl, { _id: id });
|
|
|
- console.log(res.data.isEnabled);
|
|
|
- setState(res.data.isEnabled);
|
|
|
- // mutate();
|
|
|
- // return data;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res = await apiv3Post(reqUrl, { _id: id });
|
|
|
+ setState(res.data.isEnabled);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ console.log('pluginIsEnabled', err);
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ mutate();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
return (
|