Futa Arai 2 лет назад
Родитель
Сommit
f5f5cfe21a

+ 2 - 2
apps/app/src/client/services/create-page/use-create-page-and-transit.tsx

@@ -2,7 +2,7 @@ import { useCallback, useState } from 'react';
 
 import { useRouter } from 'next/router';
 
-import { exist, nonUserRelatedGroupsGranted } from '~/client/services/page-operation';
+import { exist, getIsNonUserRelatedGroupsGranted } from '~/client/services/page-operation';
 import type { IApiv3PageCreateParams } from '~/interfaces/apiv3';
 import { useGrantedGroupsInheritanceSelectModal } from '~/stores/modal';
 import { useCurrentPagePath } from '~/stores/page';
@@ -64,7 +64,7 @@ export const useCreatePageAndTransit: UseCreatePageAndTransit = () => {
     // Once selected, the request with same params(+ onlyInheritUserRelatedGrantedGroups) and opts will be sent here.
     if (params.parentPath != null && params?.onlyInheritUserRelatedGrantedGroups == null) {
       try {
-        const { isNonUserRelatedGroupsGranted } = await nonUserRelatedGroupsGranted(params.parentPath);
+        const { isNonUserRelatedGroupsGranted } = await getIsNonUserRelatedGroupsGranted(params.parentPath);
         if (isNonUserRelatedGroupsGranted) {
           openGrantedGroupsInheritanceSelectModal(params, opts);
           return;

+ 1 - 1
apps/app/src/client/services/page-operation.ts

@@ -160,7 +160,7 @@ interface NonUserRelatedGroupsGrantedResponse {
   isNonUserRelatedGroupsGranted: boolean,
 }
 
-export const nonUserRelatedGroupsGranted = async(path: string): Promise<NonUserRelatedGroupsGrantedResponse> => {
+export const getIsNonUserRelatedGroupsGranted = async(path: string): Promise<NonUserRelatedGroupsGrantedResponse> => {
   const res = await apiv3Get<NonUserRelatedGroupsGrantedResponse>('/page/non-user-related-groups-granted', { path });
   return res.data;
 };

+ 10 - 7
apps/app/src/components/GrantedGroupsInheritanceSelectModal.tsx

@@ -1,7 +1,9 @@
 import { useState } from 'react';
 
 import { useTranslation } from 'react-i18next';
-import { Modal, ModalHeader, ModalBody } from 'reactstrap';
+import {
+  Modal, ModalHeader, ModalBody, ModalFooter,
+} from 'reactstrap';
 
 import { useCreatePageAndTransit } from '~/client/services/create-page';
 import { useGrantedGroupsInheritanceSelectModal } from '~/stores/modal';
@@ -29,11 +31,11 @@ export const GrantedGroupsInheritanceSelectModal = (): JSX.Element => {
       isOpen={isOpened}
       toggle={() => closeModal()}
     >
-      <ModalHeader tag="h4" toggle={() => closeModal()} className="bg-primary text-light">
+      <ModalHeader tag="h4" toggle={() => closeModal()} className="text-light">
         {t('modal_granted_groups_inheritance_select.select_granted_groups')}
       </ModalHeader>
       <ModalBody>
-        <div className="p-3">
+        <div className="px-3 pt-3">
           <div className="form-check radio-primary mb-3">
             <input
               type="radio"
@@ -47,7 +49,7 @@ export const GrantedGroupsInheritanceSelectModal = (): JSX.Element => {
               {t('modal_granted_groups_inheritance_select.inherit_all_granted_groups_from_parent')}
             </label>
           </div>
-          <div className="form-check radio-primary mb-4">
+          <div className="form-check radio-primary">
             <input
               type="radio"
               id="onlyInheritRelatedGroupsRadio"
@@ -60,11 +62,12 @@ export const GrantedGroupsInheritanceSelectModal = (): JSX.Element => {
               {t('modal_granted_groups_inheritance_select.only_inherit_related_groups')}
             </label>
           </div>
-          <div className="text-center">
-            <button className="btn btn-primary" type="button" onClick={onCreateBtnClick}>{t('modal_granted_groups_inheritance_select.create_page')}</button>
-          </div>
         </div>
       </ModalBody>
+      <ModalFooter className="grw-modal-footer">
+        <button type="button" className="me-2 btn btn-secondary" onClick={() => closeModal()}>{t('Cancel')}</button>
+        <button className="btn btn-primary" type="button" onClick={onCreateBtnClick}>{t('modal_granted_groups_inheritance_select.create_page')}</button>
+      </ModalFooter>
     </Modal>
   );
 };

+ 4 - 0
apps/app/src/server/routes/apiv3/page/index.ts

@@ -645,6 +645,10 @@ module.exports = (crowi) => {
     try {
       const page = await Page.findByPathAndViewer(path, user, null, true);
 
+      if (page == null) {
+        return res.apiv3Err(new ErrorV3('Page is unreachable or empty.', 'page_unreachable_or_empty'), 400);
+      }
+
       if (page.grant !== PageGrant.GRANT_USER_GROUP) {
         return res.apiv3({ isNonUserRelatedGroupsGranted: false });
       }

+ 4 - 2
apps/app/src/stores/modal.tsx

@@ -66,10 +66,12 @@ export const useGrantedGroupsInheritanceSelectModal = (
     'grantedGroupsInheritanceSelectModalStatus', status, { fallbackData: initialData },
   );
 
+  const { mutate } = swrResponse;
+
   return {
     ...swrResponse,
-    open: (params?: IApiv3PageCreateParams, opts?: CreatePageAndTransitOpts) => swrResponse.mutate({ isOpened: true, params, opts }),
-    close: () => swrResponse.mutate({ isOpened: false }),
+    open: useCallback((params?: IApiv3PageCreateParams, opts?: CreatePageAndTransitOpts) => mutate({ isOpened: true, params, opts }), [mutate]),
+    close: useCallback(() => mutate({ isOpened: false }), [mutate]),
   };
 };