|
|
@@ -1,26 +1,27 @@
|
|
|
-import React, { type ReactNode, useCallback } from 'react';
|
|
|
+import React, { type ReactNode, useCallback, useState } from 'react';
|
|
|
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
|
|
|
import { EditorMode, useIsDeviceSmallerThanMd } from '~/stores/ui';
|
|
|
|
|
|
+import { useOnPageEditorModeButtonClicked } from './hooks';
|
|
|
+
|
|
|
import styles from './PageEditorModeManager.module.scss';
|
|
|
|
|
|
|
|
|
type PageEditorModeButtonProps = {
|
|
|
currentEditorMode: EditorMode,
|
|
|
editorMode: EditorMode,
|
|
|
- icon: ReactNode,
|
|
|
- label: ReactNode,
|
|
|
+ children?: ReactNode,
|
|
|
isBtnDisabled?: boolean,
|
|
|
onClick?: (mode: EditorMode) => void,
|
|
|
}
|
|
|
const PageEditorModeButton = React.memo((props: PageEditorModeButtonProps) => {
|
|
|
const {
|
|
|
- currentEditorMode, isBtnDisabled, editorMode, icon, label, onClick,
|
|
|
+ currentEditorMode, isBtnDisabled, editorMode, children, onClick,
|
|
|
} = props;
|
|
|
|
|
|
- const classNames = ['btn btn-outline-primary px-1'];
|
|
|
+ const classNames = ['btn btn-outline-primary py-1 px-2 d-flex align-items-center justify-content-center'];
|
|
|
if (currentEditorMode === editorMode) {
|
|
|
classNames.push('active');
|
|
|
}
|
|
|
@@ -35,36 +36,43 @@ const PageEditorModeButton = React.memo((props: PageEditorModeButtonProps) => {
|
|
|
onClick={() => onClick?.(editorMode)}
|
|
|
data-testid={`${editorMode}-button`}
|
|
|
>
|
|
|
- <span className="me-1">{icon}</span>
|
|
|
- <span>{label}</span>
|
|
|
+ {children}
|
|
|
</button>
|
|
|
);
|
|
|
});
|
|
|
|
|
|
type Props = {
|
|
|
editorMode: EditorMode | undefined,
|
|
|
- onPageEditorModeButtonClicked?: (editorMode: EditorMode) => void,
|
|
|
- isBtnDisabled?: boolean,
|
|
|
+ isBtnDisabled: boolean,
|
|
|
+ path?: string,
|
|
|
+ grant?: number,
|
|
|
+ grantUserGroupId?: string
|
|
|
}
|
|
|
|
|
|
export const PageEditorModeManager = (props: Props): JSX.Element => {
|
|
|
const {
|
|
|
editorMode = EditorMode.View,
|
|
|
isBtnDisabled,
|
|
|
- onPageEditorModeButtonClicked,
|
|
|
+ path,
|
|
|
+ grant,
|
|
|
+ grantUserGroupId,
|
|
|
} = props;
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
+ const [isCreating, setIsCreating] = useState(false);
|
|
|
+
|
|
|
const { data: isDeviceSmallerThanMd } = useIsDeviceSmallerThanMd();
|
|
|
|
|
|
- const pageEditorModeButtonClickedHandler = useCallback((viewType) => {
|
|
|
- if (isBtnDisabled ?? false) {
|
|
|
+ const onPageEditorModeButtonClicked = useOnPageEditorModeButtonClicked(setIsCreating, path, grant, grantUserGroupId);
|
|
|
+ const _isBtnDisabled = isCreating || isBtnDisabled;
|
|
|
+
|
|
|
+ const pageEditorModeButtonClickedHandler = useCallback((viewType: EditorMode) => {
|
|
|
+ if (_isBtnDisabled) {
|
|
|
return;
|
|
|
}
|
|
|
- if (onPageEditorModeButtonClicked != null) {
|
|
|
- onPageEditorModeButtonClicked(viewType);
|
|
|
- }
|
|
|
- }, [isBtnDisabled, onPageEditorModeButtonClicked]);
|
|
|
+
|
|
|
+ onPageEditorModeButtonClicked?.(viewType);
|
|
|
+ }, [_isBtnDisabled, onPageEditorModeButtonClicked]);
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
@@ -78,21 +86,21 @@ export const PageEditorModeManager = (props: Props): JSX.Element => {
|
|
|
<PageEditorModeButton
|
|
|
currentEditorMode={editorMode}
|
|
|
editorMode={EditorMode.View}
|
|
|
- isBtnDisabled={isBtnDisabled}
|
|
|
+ isBtnDisabled={_isBtnDisabled}
|
|
|
onClick={pageEditorModeButtonClickedHandler}
|
|
|
- icon={<i className="icon-control-play" />}
|
|
|
- label={t('view')}
|
|
|
- />
|
|
|
+ >
|
|
|
+ <span className="material-symbols-outlined fs-4">play_arrow</span>{t('View')}
|
|
|
+ </PageEditorModeButton>
|
|
|
)}
|
|
|
{(!isDeviceSmallerThanMd || editorMode === EditorMode.View) && (
|
|
|
<PageEditorModeButton
|
|
|
currentEditorMode={editorMode}
|
|
|
editorMode={EditorMode.Editor}
|
|
|
- isBtnDisabled={isBtnDisabled}
|
|
|
+ isBtnDisabled={_isBtnDisabled}
|
|
|
onClick={pageEditorModeButtonClickedHandler}
|
|
|
- icon={<i className="icon-note" />}
|
|
|
- label={t('Edit')}
|
|
|
- />
|
|
|
+ >
|
|
|
+ <span className="material-symbols-outlined me-1 fs-5">edit_square</span>{t('Edit')}
|
|
|
+ </PageEditorModeButton>
|
|
|
)}
|
|
|
</div>
|
|
|
</>
|