Просмотр исходного кода

refactor: enhance AiAssistantManagementHeader to accept back navigation props

Shun Miyazawa 8 месяцев назад
Родитель
Сommit
138f99aa9b

+ 14 - 5
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementHeader.tsx

@@ -1,12 +1,19 @@
-import type { JSX } from 'react';
+import { type JSX, useMemo } from 'react';
 
 import { useTranslation } from 'react-i18next';
 import { ModalHeader } from 'reactstrap';
 
 import { useAiAssistantManagementModal, AiAssistantManagementModalPageMode } from '../../../stores/ai-assistant';
 
+type Props = {
+  label?: string;
+  backToPageMode?: AiAssistantManagementModalPageMode;
+  hideBackButton?: boolean;
+}
+
+export const AiAssistantManagementHeader = (props: Props): JSX.Element => {
+  const { label, backToPageMode, hideBackButton } = props;
 
-export const AiAssistantManagementHeader = (): JSX.Element => {
   const { t } = useTranslation();
   const { data, close, changePageMode } = useAiAssistantManagementModal();
 
@@ -19,9 +26,11 @@ export const AiAssistantManagementHeader = (): JSX.Element => {
       )}
     >
       <div className="d-flex align-items-center">
-        <button type="button" className="btn p-0 me-3" onClick={() => changePageMode(AiAssistantManagementModalPageMode.HOME)}>
-          <span className="material-symbols-outlined text-primary">chevron_left</span>
-        </button>
+        { !hideBackButton && (
+          <button type="button" className="btn p-0 me-3" onClick={() => changePageMode(backToPageMode ?? AiAssistantManagementModalPageMode.HOME)}>
+            <span className="material-symbols-outlined text-primary">chevron_left</span>
+          </button>
+        )}
         <span>{t(`modal_ai_assistant.page_mode_title.${data?.pageMode}`)}</span>
       </div>
     </ModalHeader>

+ 1 - 1
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementPageSelectionMethod.tsx

@@ -35,7 +35,7 @@ const SelectionButton = (props: { icon: string, label: string, onClick: () => vo
 export const AiAssistantManagementPageSelectionMethod = (): JSX.Element => {
   return (
     <>
-      <AiAssistantManagementHeader />
+      <AiAssistantManagementHeader hideBackButton/>
 
       <ModalBody className="px-4">
         <h4 className="text-center mb-4">

+ 1 - 1
apps/app/src/features/openai/client/stores/ai-assistant.tsx

@@ -17,7 +17,7 @@ export const AiAssistantManagementModalPageMode = {
   PAGE_SELECTION_METHOD: 'page-selection-method',
 } as const;
 
-type AiAssistantManagementModalPageMode = typeof AiAssistantManagementModalPageMode[keyof typeof AiAssistantManagementModalPageMode];
+export type AiAssistantManagementModalPageMode = typeof AiAssistantManagementModalPageMode[keyof typeof AiAssistantManagementModalPageMode];
 
 type AiAssistantManagementModalStatus = {
   isOpened: boolean,