Skip to content

Commit

Permalink
Merge pull request #7949 from weseek/imprv/use-new-toastr
Browse files Browse the repository at this point in the history
imprv: Clean up old toastr
  • Loading branch information
yuki-takei authored Aug 3, 2023
2 parents 4824f06 + a7342d6 commit ddcedd4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { useTranslation } from 'next-i18next';
import {
Modal, ModalHeader, ModalBody, ModalFooter,
} from 'reactstrap';
import * as toastr from 'toastr';

import { apiPost } from '~/client/util/apiv1-client';

// import { toastSuccess, toastError } from '~/client/util/toastr';
import { toastError, toastSuccess } from '~/client/util/toastr';


const GROUPS_PAGE = [
Expand Down Expand Up @@ -72,37 +70,19 @@ const SelectCollectionsModal = (props: Props): JSX.Element => {
try {
// TODO: use apiv3Post
const result = await apiPost<any>('/v3/export', { collections: Array.from(selectedCollections) });
// TODO: toastSuccess, toastError

if (!result.ok) {
throw new Error('Error occured.');
}

// TODO: toastSuccess, toastError
toastr.success(undefined, 'Export process has requested.', {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '1200',
extendedTimeOut: '150',
});
toastSuccess('Export process has requested.');

onExportingRequested();
onClose();
uncheckAll();
}
catch (err) {
// TODO: toastSuccess, toastError
toastr.error(err, 'Error', {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '3000',
});
toastError(err);
}
}, [onClose, onExportingRequested, selectedCollections, uncheckAll]);

Expand Down
35 changes: 4 additions & 31 deletions apps/app/src/components/Admin/ExportArchiveDataPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useCallback, useEffect, useState } from 'react';

import { useTranslation } from 'react-i18next';
import * as toastr from 'toastr';


import { apiDelete } from '~/client/util/apiv1-client';
import { apiv3Get } from '~/client/util/apiv3-client';
import { toastError, toastSuccess } from '~/client/util/toastr';
import { useAdminSocket } from '~/stores/socket-io';

import LabeledProgressBar from './Common/LabeledProgressBar';
Expand Down Expand Up @@ -34,7 +34,6 @@ const ExportArchiveDataPage = (): JSX.Element => {
apiv3Get<{collections: any[]}>('/mongo/collections', {}),
apiv3Get<{status: { zipFileStats: any[], isExporting: boolean, progressList: any[] }}>('/export/status', {}),
]);
// TODO: toastSuccess, toastError

// filter only not ignored collection names
const filteredCollections = collectionsData.collections.filter((collectionName) => {
Expand Down Expand Up @@ -69,16 +68,7 @@ const ExportArchiveDataPage = (): JSX.Element => {
setExported(true);
setZipFileStats(prev => prev.concat([addedZipFileStat]));

// TODO: toastSuccess, toastError
toastr.success(undefined, `New Archive Data '${addedZipFileStat.fileName}' is added`, {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '1200',
extendedTimeOut: '150',
});
toastSuccess(`New Archive Data '${addedZipFileStat.fileName}' is added`);
});
}
}, [socket]);
Expand All @@ -89,27 +79,10 @@ const ExportArchiveDataPage = (): JSX.Element => {

setZipFileStats(prev => prev.filter(stat => stat.fileName !== fileName));

// TODO: toastSuccess, toastError
toastr.success(undefined, `Deleted ${fileName}`, {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '1200',
extendedTimeOut: '150',
});
toastSuccess(`Deleted ${fileName}`);
}
catch (err) {
// TODO: toastSuccess, toastError
toastr.error(err, 'Error', {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '3000',
});
toastError(err);
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class UploadForm extends React.Component {

try {
const { data } = await apiv3PostForm('/import/upload', formData);
// TODO: toastSuccess, toastError
this.props.onUpload(data);
}
catch (err) {
Expand Down
24 changes: 3 additions & 21 deletions apps/app/src/components/Admin/ImportData/GrowiArchiveSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import React, { Fragment } from 'react';

import { useTranslation } from 'next-i18next';
import PropTypes from 'prop-types';
import * as toastr from 'toastr';

import { apiv3Delete, apiv3Get } from '~/client/util/apiv3-client';
import { toastError, toastSuccess } from '~/client/util/toastr';

// import { toastSuccess, toastError } from '~/client/util/toastr';

import ImportForm from './GrowiArchive/ImportForm';
import UploadForm from './GrowiArchive/UploadForm';
Expand Down Expand Up @@ -59,27 +58,10 @@ class GrowiArchiveSection extends React.Component {
await apiv3Delete('/import/all');
this.resetState();

// TODO: toastSuccess, toastError
toastr.success(undefined, `Deleted ${fileName}`, {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '1200',
extendedTimeOut: '150',
});
toastSuccess(`Deleted ${fileName}`);
}
catch (err) {
// TODO: toastSuccess, toastError
toastr.error(err, 'Error', {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '3000',
});
toastError(err);
}
}

Expand Down
11 changes: 2 additions & 9 deletions apps/app/src/components/PageComment/CommentEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { useRouter } from 'next/router';
import {
Button, TabContent, TabPane,
} from 'reactstrap';
import * as toastr from 'toastr';

import { apiPostForm } from '~/client/util/apiv1-client';
import { toastError } from '~/client/util/toastr';
import { IEditorMethods } from '~/interfaces/editor-methods';
import { useSWRxPageComment, useSWRxEditingCommentsNum } from '~/stores/comment';
import {
Expand Down Expand Up @@ -200,14 +200,7 @@ export const CommentEditor = (props: CommentEditorProps): JSX.Element => {
}, [postCommentHandler]);

const apiErrorHandler = useCallback((error: Error) => {
toastr.error(error.message, 'Error occured', {
closeButton: true,
progressBar: true,
newestOnTop: false,
showDuration: '100',
hideDuration: '100',
timeOut: '3000',
});
toastError(error.message);
}, []);

const uploadHandler = useCallback(async(file) => {
Expand Down
3 changes: 0 additions & 3 deletions apps/app/src/styles/molecules/toastr.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
:root {
@import '~toastr/build/toastr';
}
@import '~react-toastify/scss/main';

0 comments on commit ddcedd4

Please sign in to comment.