Skip to content

Commit

Permalink
add toast
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed Jan 28, 2025
1 parent 8f7f4b3 commit e53527b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'bootstrap/dist/css/bootstrap.min.css';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
import 'react-toastify/dist/ReactToastify.css';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import MainNavbar from './components/Navbar.jsx';
import PageNotFound from './pages/PageNotFound.jsx';
import MainPage from './pages/MainPage.jsx';
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/AddModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useFormik } from 'formik';
import { Modal, FormGroup, FormControl, Button, Form } from 'react-bootstrap';
import { useDispatch } from 'react-redux';
import { useTranslation } from 'react-i18next';
import { toast } from 'react-toastify';
import { channelSchema } from '../utils/validate.js';
import { useAddChannelMutation, useGetChannelsQuery } from '../api/chatApi';
import { selectActiveTab } from '../slices/activeChannelSlice.js';
Expand All @@ -27,6 +28,9 @@ const AddChannel = ({ onHide }) => {
try {
const response = await addChannel({name: values.name});
dispatch(selectActiveTab(response.data));
toast.success(t('channels.create'), {
position: 'top-right',
});
onHide();
} catch (error) {
console.log(error);
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/MessageForm.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Form } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { useEffect, useRef } from 'react';
import { useRef } from 'react';
import { useFormik } from 'formik';

const MessageForm = ({ activeChannelId, username, addMessage }) => {
Expand All @@ -23,10 +23,6 @@ const MessageForm = ({ activeChannelId, username, addMessage }) => {
},
});

// useEffect(() => {
// formControlEl.current.focus();
// }, []);

return (
<div className="mt-auto px-5 py-3">
<Form className="py-1 border rounded-2" onSubmit={formik.handleSubmit} noValidate>
Expand All @@ -52,7 +48,6 @@ const MessageForm = ({ activeChannelId, username, addMessage }) => {
</svg>
<span className="visually-hidden">{t('formMesseges.button')}</span>
</Button>

</Form.Group>
</Form>
</div>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/RemoveModel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Modal, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { useRemoveChannelMutation } from '../api/chatApi';
import { useSelector, useDispatch } from 'react-redux';
import { toast } from 'react-toastify';
import { selectActiveTab, defaultChannel } from '../slices/activeChannelSlice.js';

const RemoveChannel = ({ onHide }) => {
Expand All @@ -14,6 +15,9 @@ const RemoveChannel = ({ onHide }) => {
try {
await removeChannel(id);
dispatch(selectActiveTab(defaultChannel));
toast.success(t('channels.delete'), {
position: 'top-right',
});
onHide();
} catch (err) {
console.log(err);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/RenameModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Modal, FormGroup, FormControl, Button, Form } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { useFormik } from 'formik';
import { useSelector } from 'react-redux';
import { toast } from 'react-toastify';
import { useRenameChannelMutation, useGetChannelsQuery } from '../api/chatApi';
import { channelSchema } from '../utils/validate.js';

Expand All @@ -26,6 +27,9 @@ const RenameChannel = ({ onHide }) => {
onSubmit: async (values) => {
try {
await renameChannel({name: values.name, id: channelId});
toast.success(t('channels.rename'), {
position: 'top-right',
});
onHide();
} catch (error) {
console.log(error);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/init.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18next from 'i18next';
import { I18nextProvider } from 'react-i18next';
import { ToastContainer } from 'react-toastify';
import { combineReducers, configureStore } from '@reduxjs/toolkit';
import { chatApi } from './api/chatApi.js';
import activeChannelReducer from './slices/activeChannelSlice.js';
Expand Down Expand Up @@ -62,6 +62,7 @@ const init = async () => {
return (
<Provider store={store}>
<App />
<ToastContainer />
</Provider>
);
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default {
setupChannel: 'Управление каналом',
dropdownButtonRemove: 'Удалить',
dropdownButtonRename: 'Переименовать',
create: 'Канал создан',
rename: 'Канал переименован',
delete: 'Канал удалён',
},
modal: {
name: 'Имя канала',
Expand Down

0 comments on commit e53527b

Please sign in to comment.