Skip to content

Commit

Permalink
add reputation to table with scores and add invitations and register …
Browse files Browse the repository at this point in the history
…code to registration
  • Loading branch information
romanbutora committed Jul 28, 2023
1 parent ea5a07f commit dbb5bda
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/api/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ export default class UserService {
}, { headers });
};

static signupCode = (
firstName: string,
lastName: string,
email: string,
password: string,
code: string,
) => {
const headers = { Authorization: `Bearer ${localStorage.getItem('accessToken')}` };
return factCheckBe.post<any>('/auth/register-code', {
firstName, lastName, email, password, code,
}, { headers });
};

static invite = (email: string) => {
const headers = { Authorization: `Bearer ${localStorage.getItem('accessToken')}` };
return factCheckBe.post<any>('/invitations', {
email,
}, { headers });
};

static getUserStats = () => {
const headers = { Authorization: `Bearer ${localStorage.getItem('accessToken')}` };
return factCheckBe.get<IStats>('/stats', { headers });
Expand Down
93 changes: 93 additions & 0 deletions src/components/Invitation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { useEffect, useContext } from 'react';
import { useNavigate } from 'react-router-dom';
import {
Button,
Form,
Input,
Layout,
} from 'antd';

import { useRecoilValue } from 'recoil';
import { useTranslation } from 'react-i18next';
import { CloseOutlined } from '@ant-design/icons';
import usersService from '../../api/users.service';
import authAtom from '../../_state/auth';
import { NotificationContext } from '../NotificationContext/NotificationContext';

const { Content } = Layout;

const Invitation: React.FC = () => {
const auth = useRecoilValue(authAtom);
const navigate = useNavigate();
const { t } = useTranslation();
const notificationApi = useContext(NotificationContext);

useEffect(() => {
const id = auth?.user?._id;
// redirect to home if already logged in
if (id === undefined) {
navigate('/sign-in');
}
}, [auth]);

const onFinish = (values: any) => {
usersService.invite(
values.invitedEmail,
).then(() => {
notificationApi.info({
message: t('successfully_invited'),
description: t('gained_30'),
icon: <img alt="leaders" width="50%" src={`${process.env.PUBLIC_URL}/pictures/experience.png`} style={{ marginRight: '5%' }} />,
});
}).catch((err: any) => {
notificationApi.info({
message: err.response.data.message,
icon: <CloseOutlined />,
});
});
};

return (
<Content className="site-layout" style={{ paddingLeft: '0%', padding: '1%', paddingTop: '5%' }}>
<p>{t('invite_about')}</p>
<Form
name="basic"
wrapperCol={{
span: 24,
}}
initialValues={{
remember: true,
}}
onFinish={onFinish}
autoComplete="off"
>

<Form.Item
name="invitedEmail"
rules={[
{
required: true,
message: t('please_first'),
min: 4,
},
]}
>
<Input placeholder={t('email')} id="emailInvite" />
</Form.Item>

<Form.Item
wrapperCol={{
offset: 0,
span: 24,
}}
>
<Button block type="default" htmlType="submit" id="submitRegister">
{t('invite')}
</Button>
</Form.Item>
</Form>
</Content>
);
};

export default Invitation;
7 changes: 7 additions & 0 deletions src/components/ProfileSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MyArticles from '../MyArticles';
import MyClaims from '../MyClaims';
import Scoreboard from '../Scoreboard';
import UserReviews from '../UserReviews';
import Invitation from '../Invitation';

const { Content } = Layout;

Expand Down Expand Up @@ -46,6 +47,9 @@ const ProfileSidebar: React.FC<Props> = ({ userid }) => {
<Nav.Item>
<Nav.Link eventKey="5th" className="whites myReviewsProfile">{t('my_reviews')}</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link eventKey="6th" className="whites invitationsProfile">{t('invite')}</Nav.Link>
</Nav.Item>
</Nav>
</Col>
<Col sm={9} xl={9} style={{ marginLeft: '1%' }}>
Expand All @@ -67,6 +71,9 @@ const ProfileSidebar: React.FC<Props> = ({ userid }) => {
<Tab.Pane eventKey="5th">
<UserReviews userid={userid} />
</Tab.Pane>
<Tab.Pane eventKey="6th">
<Invitation />
</Tab.Pane>
</Tab.Content>
</Col>
</Row>
Expand Down
7 changes: 6 additions & 1 deletion src/components/Scoreboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ const Scoreboard: React.FC = () => {
},
{
title: t('name'),
dataIndex: 'fullName', // Use a custom dataIndex for the merged value
render: (text: string, record: any) => `${record.firstName} ${record.lastName}`, // Combine firstName and lastName
},
{
title: t('reputation'),
// eslint-disable-next-line no-useless-concat
dataIndex: 'firstName',
dataIndex: 'reputation',
},
{
title: 'Level',
Expand Down
18 changes: 16 additions & 2 deletions src/layouts/authentication/sign-up/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const SignUp: React.FC = () => {
}, [auth, navigate]);

const onFinish = (values: any) => {
usersService.signup(
usersService.signupCode(
values.firstname,
values.lastname,
values.email,
values.password,
values.code,
).then((res) => {
setAuth(res.data);
localStorage.setItem('user', JSON.stringify(res.data));
Expand Down Expand Up @@ -98,7 +99,7 @@ const SignUp: React.FC = () => {
},
]}
>
<Input placeholder="First name" id="firstNameRegister" />
<Input placeholder={t('first_name')} id="firstNameRegister" />
</Form.Item>

<Form.Item
Expand Down Expand Up @@ -140,6 +141,19 @@ const SignUp: React.FC = () => {
<Input.Password placeholder={t('password')} id="passwordRegister" />
</Form.Item>

<Form.Item
name="code"
rules={[
{
required: true,
message: t('please_first'),
min: 4,
},
]}
>
<Input placeholder={t('code')} id="codeRegister" />
</Form.Item>

<Form.Item
wrapperCol={{
offset: 0,
Expand Down
7 changes: 6 additions & 1 deletion src/locales/cz/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@
"positive_votes_desc": "pozitivní hlasy sestupně",
"positive_votes_asc": "pozitívne hlasy vzestupně",
"date_desc": "dátum sestupně",
"date_asc": "dátum vzestupně"
"date_asc": "dátum vzestupně",
"reputation": "Reputace",
"code": "Verifikační kód",
"invite": "Pozvat užívatele",
"successfully_invited": "Užívatel byl pozvaný",
"invite_about": "Pošlite pozvánku do aplikace jinému užívatelovi. Užívatelovi příde mail s registračním kódem"
}
7 changes: 6 additions & 1 deletion src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@
"positive_votes_desc": "positive votes descending",
"positive_votes_asc": "positive votes ascending",
"date_desc": "date descending",
"date_asc": "date ascending"
"date_asc": "date ascending",
"reputation": "Reputation",
"code": "Verification code",
"invite": "Invite user",
"successfully_invited": "User was invited",
"invite_about": "Send invitation to application to another user. User receives email with registration code"
}
7 changes: 6 additions & 1 deletion src/locales/sk/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@
"positive_votes_desc": "pozitívne hlasy zostupne",
"positive_votes_asc": "pozitívne hlasy vzostupne",
"date_desc": "dátum zostupne",
"date_asc": "dátum vzostupne"
"date_asc": "dátum vzostupne",
"reputation": "Reputácia",
"code": "Verifikačný kód",
"invite": "Pozvať používateľa",
"successfully_invited": "Používateľ bol pozvaný",
"invite_about": "Pošlite pozvánku do aplikácie inému používateľovi. Používateľovi príde mail s registračným kódom"
}

0 comments on commit dbb5bda

Please sign in to comment.