Skip to content

Commit

Permalink
add vite.config
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatyana-js committed Dec 28, 2024
1 parent 381cc42 commit f42fc6c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
4 changes: 2 additions & 2 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const App = () => {
<div className="d-flex h-100 flex-column">
<Navbar bg="white" expand="lg" className="shadow-sm">
<Container>
<Navbar.Brand href="/">Hexlet Chat</Navbar.Brand>
<button type="button" className="btn btn-primary">Выйти</button>
<Navbar.Brand href="/">{t('navBar.title')}</Navbar.Brand>
<button type="button" className="btn btn-primary">{t('navBar.button')}</button>
</Container>
</Navbar>
<AuthProvider>
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export default {
password: 'Пароль',
span: 'Нет аккаунта?',
signUp: 'Регистрация',
error: 'Неверное имя пользователя или пароль',
},
navBar: {
title: 'Hexlet Chat',
button: 'Выйти',
}
// singUpForm: {
// username: ''
// }
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/pages/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useFormik } from 'formik';
import { useTranslation } from 'react-i18next';
import avatarLogin from '../assets/avatarLogin.jpg';
import useAuth from '../hooks/index.jsx';
import routes from '../utils/routes.js';
import router from '../utils/routes.js';
import userSchema from '../utils/validate.js';


Expand All @@ -30,10 +30,9 @@ const LoginPage = () => {
onSubmit: async (values) => {
setAuthFailed(false);
try {
const res = await axios.post(routes.loginPath, values);
const res = await axios.post(router.loginPath, values);
console.log(res);
localStorage.setItem('token', res.data.token);
localStorage.setItem('username', res.data.username);
auth.logIn();
navigate(routes.mainPath);
} catch (err) {
Expand Down Expand Up @@ -70,7 +69,7 @@ const LoginPage = () => {
onChange={formik.handleChange}
value={formik.values.username}
isInvalid={authFailed}
ref={inpitEl}
ref={inputEl}
/>
<Form.Label>{t('loginForm.username')}</Form.Label>
</Form.Group>
Expand All @@ -84,9 +83,12 @@ const LoginPage = () => {
onChange={formik.handleChange}
value={formik.values.password}
isInvalid={authFailed}
ref={inpitEl}
ref={inputEl}
/>
<Form.Label>{t('loginForm.password')}</Form.Label>
<Form.Control.Feedback type="invalid">
{t('loginForm.error')}
</Form.Control.Feedback>
</Form.Group>
<Button type="submit" variant="outline-primary" className="w-100 mb-3">{t('loginForm.title')}</Button>
</fieldset>
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/store/channelsSlice.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// import { createSlice } from '@reduxjs/toolkit';
import { createSlice } from '@reduxjs/toolkit';

// const initialState = {
// channels: [],
// activeChannel: 1,
// };
const initialState = {
channels: [],
activeChannel: 1,
};

// const channelsSlice = createSlice({
// name: 'channels',
// initialState,
// reducers: {
const channelsSlice = createSlice({
name: 'channels',
initialState,
reducers: {

// }
// });
}
});

// export const { actions } = channelsSlice;
// export default channelsSlice.reducer;
export const { actions } = channelsSlice;
export default channelsSlice.reducer;
14 changes: 7 additions & 7 deletions frontend/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// import { configureStore } from '@reduxjs/toolkit';
// import channelsReducer from './channelsSlice';
import { configureStore } from '@reduxjs/toolkit';
import channelsReducer from './channelsSlice';

// export default configureStore({
// reducer: {
// channels: channelsReducer,
// }
// });
export default configureStore({
reducer: {
channels: channelsReducer,
}
});
4 changes: 2 additions & 2 deletions frontend/src/utils/routes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const apiPath = '/api/v1';
// const apiPath = '/api/v1';

export default {
loginPath: '/login',
loginPath: '/api/v1/login',
mainPath: '/',
};
2 changes: 1 addition & 1 deletion frontend/src/utils/validate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { object, string } from 'yup';

const userSchema = () => object().shape({
username: string().required(),
username: string().min(3).required(),
password: string().required(),
});

Expand Down
5 changes: 3 additions & 2 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
server: {
port: 5002,
// port: 5002,
proxy: {
// Проксируем запросы к API
'/api': {
target: 'http://localhost:5001',
changeOrigin: true,
},
// Проксируем WebSocket соединения
'/socket.io': {
target: 'ws://localhost:5001',
ws: true,
rewriteWsOrigin: true,
changeOrigin: true,
},
},
},
Expand Down

0 comments on commit f42fc6c

Please sign in to comment.