import React, { useState } from 'react'; import Link from 'next/link'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import { apiv3Post } from '~/client/util/apiv3-client'; import { useSWRxPlugin } from '~/stores/plugin'; import styles from './PluginCard.module.scss'; type Props = { id: string, name: string, url: string, description: string, } export const PluginCard = (props: Props): JSX.Element => { const { id, name, url, description, } = props; const { data, mutate } = useSWRxPlugin(id); if (data == null) { return <>; } const PluginCardButton = (): JSX.Element => { const [isEnabled, setState] = useState(data.data.isEnabled); const onChangeHandler = async() => { const reqUrl = '/plugins/switch-isenabled'; try { const res = await apiv3Post(reqUrl, { _id: id }); setState(res.data.isEnabled); const pluginState = !isEnabled ? 'Enabled' : 'Disabled'; toastSuccess(`${pluginState} Plugin `); } catch (err) { toastError('pluginIsEnabled', err); } finally { mutate(); } }; return (
); }; const PluginDeleteButton = (): JSX.Element => { const onClickPluginDeleteBtnHandler = async() => { const reqUrl = '/plugins/deleted'; try { await apiv3Post(reqUrl, { _id: id, name }); toastSuccess(`${name} Deleted`); } catch (err) { toastError('pluginDelete', err); } finally { mutate(); } }; return (
); }; return (

{name}

{description}

{/* {topics?.map((topic: string) => { return ( {topic} ); })} */}

{/* {owner.login === 'weseek' ? : <>} {owner.login} */} {/* {stargazersCount} */}

); };