|
|
@@ -1,10 +1,8 @@
|
|
|
-import React, { useState, useCallback } from 'react';
|
|
|
+import React, { useState } from 'react';
|
|
|
|
|
|
-import { useTranslation } from 'react-i18next';
|
|
|
import { Dropdown } from 'reactstrap';
|
|
|
|
|
|
-import { useCreateTemplatePage } from '~/client/services/create-page';
|
|
|
-import { toastError } from '~/client/util/toastr';
|
|
|
+import { useCreateTemplatePage, useToastrOnError } from '~/client/services/create-page';
|
|
|
|
|
|
import { CreateButton } from './CreateButton';
|
|
|
import { DropendMenu } from './DropendMenu';
|
|
|
@@ -12,20 +10,6 @@ import { DropendToggle } from './DropendToggle';
|
|
|
import { useCreateNewPage, useCreateTodaysMemo } from './hooks';
|
|
|
|
|
|
|
|
|
-const useToastrOnError = <P, R>(method?: (param?: P) => Promise<R|undefined>): (param?: P) => Promise<R|undefined> => {
|
|
|
- const { t } = useTranslation('commons');
|
|
|
-
|
|
|
- return useCallback(async(param) => {
|
|
|
- try {
|
|
|
- return await method?.(param);
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- toastError(t('toaster.create_failed', { target: 'a page' }));
|
|
|
- }
|
|
|
- }, [method, t]);
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
export const PageCreateButton = React.memo((): JSX.Element => {
|
|
|
const [isHovered, setIsHovered] = useState(false);
|
|
|
|