Procházet zdrojové kódy

125483 remove mutate from PlaginCard and Extention

soumaeda před 2 roky
rodič
revize
af7ef496a1

+ 2 - 5
apps/app/src/components/Layout/AdminLayout.tsx

@@ -13,11 +13,8 @@ import styles from './Admin.module.scss';
 const PageCreateModal = dynamic(() => import('../PageCreateModal'), { ssr: false });
 const SystemVersion = dynamic(() => import('../SystemVersion'), { ssr: false });
 const HotkeysManager = dynamic(() => import('../Hotkeys/HotkeysManager'), { ssr: false });
-const PluginDeleteModal = dynamic(() => import(
-  '../../features/growi-plugin/client/components/Admin/PluginsExtensionPageContents/PluginDeleteModal'
-).then(
-  mod => mod.PluginDeleteModal,
-), { ssr: false });
+const PluginDeleteModal = dynamic(() => import('~/features/growi-plugin/client/components/Admin/PluginsExtensionPageContents/PluginDeleteModal')
+  .then(mod => mod.PluginDeleteModal), { ssr: false });
 
 
 type Props = {

+ 0 - 1
apps/app/src/features/growi-plugin/client/components/Admin/PluginsExtensionPageContents/PluginCard.tsx

@@ -15,7 +15,6 @@ type Props = {
   isEnalbed: boolean,
   desc?: string,
   onDelete: () => void,
-  mutate: () => void,
 }
 
 export const PluginCard = (props: Props): JSX.Element => {

+ 11 - 32
apps/app/src/features/growi-plugin/client/components/Admin/PluginsExtensionPageContents/PluginDeleteModal.tsx

@@ -42,45 +42,24 @@ export const PluginDeleteModal: React.FC = () => {
     }
   }, [id, closePluginDeleteModal, t, mutate]);
 
-  const headerContent = () => {
-    return (
-      <span>
-        <i className="icon-fw icon-fire"></i>
-        {t('plugins.confirm')}
-      </span>
-    );
-  };
-
-  const bodyContent = () => {
-
-    return (
-      <div className="card well mt-2 p-2" key={id}>
-        <Link href={`${url}`} legacyBehavior>{name}</Link>
-      </div>
-    );
-  };
-
-  const footerContent = () => {
-    return (
-      <>
-        <Button color="danger" onClick={onClickDeleteButtonHandler}>
-          <i className="icon-fw icon-fire"></i>
-          {t('Delete')}
-        </Button>
-      </>
-    );
-  };
-
   return (
     <Modal isOpen={isOpen} toggle={toggleHandler}>
       <ModalHeader tag="h4" toggle={toggleHandler} className="bg-danger text-light" name={name}>
-        {headerContent()}
+        <span>
+          <i className="icon-fw icon-fire"></i>
+          {t('plugins.confirm')}
+        </span>
       </ModalHeader>
       <ModalBody>
-        {bodyContent()}
+        <div className="card well mt-2 p-2" key={id}>
+          <Link href={`${url}`} legacyBehavior>{name}</Link>
+        </div>
       </ModalBody>
       <ModalFooter>
-        {footerContent()}
+        <Button color="danger" onClick={onClickDeleteButtonHandler}>
+          <i className="icon-fw icon-fire"></i>
+          {t('Delete')}
+        </Button>
       </ModalFooter>
     </Modal>
   );

+ 0 - 1
apps/app/src/features/growi-plugin/client/components/Admin/PluginsExtensionPageContents/PluginsExtensionPageContents.tsx

@@ -74,7 +74,6 @@ export const PluginsExtensionPageContents = (): JSX.Element => {
                       isEnalbed={pluginIsEnabled}
                       desc={pluginDiscription}
                       onDelete={onDeleteClicked}
-                      mutate={mutate}
                     />
                   );
                 })}

+ 3 - 13
apps/app/src/stores/modal.tsx

@@ -757,12 +757,6 @@ type PluginDeleteModalUtils = {
   close(): void,
 }
 
-export interface PluginData {
-  id: string;
-  name: string;
-  url: string;
-}
-
 export const usePluginDeleteModal = (): SWRResponse<PluginDeleteModalStatus, Error> & PluginDeleteModalUtils => {
   const initialStatus: PluginDeleteModalStatus = {
     isOpen: false,
@@ -775,7 +769,6 @@ export const usePluginDeleteModal = (): SWRResponse<PluginDeleteModalStatus, Err
   const { mutate } = swrResponse;
 
   const open = useCallback((plugin: IGrowiPluginHasId) => {
-
     mutate({
       isOpen: true,
       name: plugin.meta.name,
@@ -785,12 +778,9 @@ export const usePluginDeleteModal = (): SWRResponse<PluginDeleteModalStatus, Err
   }, [mutate]);
 
   const close = useCallback((): void => {
-    mutate({
-      isOpen: false,
-      name: '',
-      url: '',
-      id: '',
-    });
+    mutate(
+      initialStatus,
+    );
   }, [mutate]);
 
   return {