|
@@ -3,21 +3,48 @@ import React, { useState } from 'react';
|
|
|
|
|
|
|
|
import Link from 'next/link';
|
|
import Link from 'next/link';
|
|
|
|
|
|
|
|
|
|
+import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
|
|
+import { useSWRxPlugin } from '~/stores/plugin';
|
|
|
|
|
+
|
|
|
import styles from './PluginCard.module.scss';
|
|
import styles from './PluginCard.module.scss';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
type Props = {
|
|
type Props = {
|
|
|
|
|
+ id: string,
|
|
|
|
|
+ isEnabled: boolean,
|
|
|
name: string,
|
|
name: string,
|
|
|
url: string,
|
|
url: string,
|
|
|
description: string,
|
|
description: string,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const PluginCard = (props: Props): JSX.Element => {
|
|
export const PluginCard = (props: Props): JSX.Element => {
|
|
|
|
|
+
|
|
|
const {
|
|
const {
|
|
|
- name, url, description,
|
|
|
|
|
|
|
+ id, isEnabled, name, url, description,
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
+ const { data } = useSWRxPlugin(id);
|
|
|
|
|
+
|
|
|
|
|
+ if (data == null) {
|
|
|
|
|
+ return <></>;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('first', data.data.isEnabled);
|
|
|
const PluginCardButton = (): JSX.Element => {
|
|
const PluginCardButton = (): JSX.Element => {
|
|
|
- const [isEnabled, setIsEnabled] = useState(true);
|
|
|
|
|
|
|
+ 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;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className={`${styles.plugin_card}`}>
|
|
<div className={`${styles.plugin_card}`}>
|
|
@@ -26,7 +53,7 @@ export const PluginCard = (props: Props): JSX.Element => {
|
|
|
<input
|
|
<input
|
|
|
type="checkbox"
|
|
type="checkbox"
|
|
|
className="switch__input"
|
|
className="switch__input"
|
|
|
- onChange={() => setIsEnabled(!isEnabled)}
|
|
|
|
|
|
|
+ onChange={() => onChangeHandler()}
|
|
|
checked={isEnabled}
|
|
checked={isEnabled}
|
|
|
/>
|
|
/>
|
|
|
<span className="switch__content"></span>
|
|
<span className="switch__content"></span>
|