├── .gitignore
├── .prettierrc
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── App.css
├── App.js
├── App.test.js
├── api
├── axios.js
├── endpoints.js
└── index.js
├── components
├── AddLinksForm
│ └── index.js
├── AddProfileImage
│ └── index.js
├── AppContent
│ ├── AppContent.module.css
│ └── index.js
├── AppHeader
│ ├── AppHeader.module.css
│ └── index.js
├── AppLayout
│ └── index.js
├── EditProfileForm
│ └── index.js
└── ProfileBox
│ ├── ProfileBox.module.css
│ └── index.js
├── context
└── profileContext.js
├── index.css
├── index.js
├── logo.svg
├── pages
├── AddLinks.js
├── ProfileDetails.js
├── SharedProfile.js
└── ViewProfile.js
├── reportWebVitals.js
└── setupTests.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 | .env
21 |
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
26 | .idea
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "semi": true,
4 | "printWidth": 80,
5 | "trailingComma": "none"
6 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Project Dependencies
6 | 1. NodeJS
7 | 2. Backend Server Running (Visit README file of backend rpeository for guide)
8 |
9 | ## Environment Variables
10 | Set the following environment variables:
11 | ```
12 | REACT_APP_API_URL=
13 | REACT_APP_FE_URL=
14 | ```
15 |
16 | ## Available Scripts
17 |
18 | In the project directory, you can run:
19 |
20 | ### `npm install`
21 |
22 | Installs the dependencies of the project.
23 |
24 | ### `npm start`
25 |
26 | Runs the app in the development mode.\
27 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
28 |
29 | The page will reload when you make changes.\
30 | You may also see any lint errors in the console.
31 |
32 | ### `npm test`
33 |
34 | Launches the test runner in the interactive watch mode.\
35 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
36 |
37 | ### `npm run build`
38 |
39 | Builds the app for production to the `build` folder.\
40 | It correctly bundles React in production mode and optimizes the build for the best performance.
41 |
42 | The build is minified and the filenames include the hashes.\
43 | Your app is ready to be deployed!
44 |
45 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
46 |
47 | ### `npm run eject`
48 |
49 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
50 |
51 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
52 |
53 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
54 |
55 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
56 |
57 | ## Learn More
58 |
59 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
60 |
61 | To learn React, check out the [React documentation](https://reactjs.org/).
62 |
63 | ### Code Splitting
64 |
65 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
66 |
67 | ### Analyzing the Bundle Size
68 |
69 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
70 |
71 | ### Making a Progressive Web App
72 |
73 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
74 |
75 | ### Advanced Configuration
76 |
77 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
78 |
79 | ### Deployment
80 |
81 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
82 |
83 | ### `npm run build` fails to minify
84 |
85 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
86 |
87 | ## Functionalities Completed in Test
88 |
89 | ### Add Links
90 | You can add your GitHub, YouTube and LinkedIn links in the Add Links
91 | page.
92 |
93 | ### Profile Details
94 | You can add your name, email and photo the Profile Details
95 | page.
96 |
97 | You can see your updated information on the left side (in computer and tab)
98 | of the screen.
99 |
100 |
101 | ### Share Profile
102 | You can go to View Profile and get a link to share you profile
103 | with others. Anyone with that link will be able to view your profile.
104 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "task-fe",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@ant-design/icons": "^5.2.6",
7 | "@testing-library/jest-dom": "^5.17.0",
8 | "@testing-library/react": "^13.4.0",
9 | "@testing-library/user-event": "^13.5.0",
10 | "antd": "^5.9.4",
11 | "axios": "^1.5.1",
12 | "react": "^18.2.0",
13 | "react-dom": "^18.2.0",
14 | "react-router-dom": "^6.16.0",
15 | "react-scripts": "5.0.1",
16 | "web-vitals": "^2.1.4"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test",
22 | "eject": "react-scripts eject"
23 | },
24 | "eslintConfig": {
25 | "extends": [
26 | "react-app",
27 | "react-app/jest"
28 | ]
29 | },
30 | "browserslist": {
31 | "production": [
32 | ">0.2%",
33 | "not dead",
34 | "not op_mini all"
35 | ],
36 | "development": [
37 | "last 1 chrome version",
38 | "last 1 firefox version",
39 | "last 1 safari version"
40 | ]
41 | },
42 | "devDependencies": {
43 | "prettier": "^3.0.3"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbasikov/task-fe/7cd387a6ace0de5b06effad0b5b1e277e236ce0d/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 | You need to enable JavaScript to run this app.
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbasikov/task-fe/7cd387a6ace0de5b06effad0b5b1e277e236ce0d/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbasikov/task-fe/7cd387a6ace0de5b06effad0b5b1e277e236ce0d/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbasikov/task-fe/7cd387a6ace0de5b06effad0b5b1e277e236ce0d/src/App.css
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
3 | import './App.css';
4 |
5 | import AddLinks from './pages/AddLinks';
6 | import ViewProfile from './pages/ViewProfile';
7 | import ProfileDetails from './pages/ProfileDetails';
8 | import AppLayout from './components/AppLayout';
9 | import ProfileContextProvider from './context/profileContext';
10 | import SharedProfile from './pages/SharedProfile';
11 |
12 | function App() {
13 | return (
14 |
15 |
16 |
17 | }>
18 | } />
19 | } />
20 | } />
21 |
22 | } />
23 | Page Not Found } />
24 | }
27 | />
28 | }
31 | />
32 |
33 |
34 |
35 | );
36 | }
37 |
38 | export default App;
39 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import { render, screen } from '@testing-library/react';
2 | import App from './App';
3 |
4 | test('renders learn react link', () => {
5 | render( );
6 | const linkElement = screen.getByText(/learn react/i);
7 | expect(linkElement).toBeInTheDocument();
8 | });
9 |
--------------------------------------------------------------------------------
/src/api/axios.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios';
2 |
3 | const Axios = axios.create({
4 | baseURL: process.env.REACT_APP_API_URL
5 | });
6 |
7 | export default Axios;
8 |
--------------------------------------------------------------------------------
/src/api/endpoints.js:
--------------------------------------------------------------------------------
1 | export const SAVE_PROFILE = 'users/add-profile-info';
2 | export const SAVE_LINKS = 'users/add-links';
3 | export const GET_TOKEN = 'users/get-shareable-token';
4 | export const GET_USER_DATA = 'users/get-user-data';
5 | export const UPLOAD_PROFILE_IMG = 'users/upload-profile-img';
6 |
--------------------------------------------------------------------------------
/src/api/index.js:
--------------------------------------------------------------------------------
1 | import Axios from './axios';
2 | import {
3 | GET_TOKEN,
4 | GET_USER_DATA,
5 | SAVE_LINKS,
6 | SAVE_PROFILE,
7 | UPLOAD_PROFILE_IMG
8 | } from './endpoints';
9 |
10 | export const saveProfileInfo = async ({
11 | userId,
12 | firstName,
13 | lastName,
14 | email,
15 | profileImgURL
16 | }) => {
17 | try {
18 | const requestData = {
19 | firstName,
20 | lastName,
21 | email,
22 | profileImgURL
23 | };
24 | if (userId) requestData.userId = userId;
25 | const response = await Axios.post(SAVE_PROFILE, requestData);
26 | return response.data.data;
27 | } catch (e) {
28 | throw new Error('Some error occurred!');
29 | }
30 | };
31 |
32 | export const saveLinks = async ({ userId, links }) => {
33 | try {
34 | const requestData = {
35 | links
36 | };
37 | if (userId) requestData.userId = userId;
38 | const response = await Axios.post(SAVE_LINKS, requestData);
39 | return response.data.data;
40 | } catch (e) {
41 | throw new Error('Some error occurred!');
42 | }
43 | };
44 |
45 | export const getShareableToken = async (userId) => {
46 | try {
47 | const response = await Axios.get(GET_TOKEN, { params: { userId } });
48 | return response.data.data.token;
49 | } catch (e) {
50 | throw new Error('Some error occurred!');
51 | }
52 | };
53 |
54 | export const getUserData = async (token) => {
55 | try {
56 | const response = await Axios.get(GET_USER_DATA, { params: { token } });
57 | return response.data.data.user;
58 | } catch (e) {
59 | throw new Error('Some error occurred!');
60 | }
61 | };
62 |
63 | export const uploadProfileImage = async (userId, profileImg) => {
64 | try {
65 | const formData = new FormData();
66 | formData.append('image', profileImg);
67 | if (userId) formData.append('userId', userId);
68 | const response = await Axios.post(UPLOAD_PROFILE_IMG, formData);
69 | return response.data.data.imgURL;
70 | } catch (e) {
71 | throw new Error('Some error occurred!');
72 | }
73 | };
74 |
--------------------------------------------------------------------------------
/src/components/AddLinksForm/index.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import { Button, Form, Input, message } from 'antd';
3 | import {
4 | GithubOutlined,
5 | LinkedinOutlined,
6 | YoutubeOutlined
7 | } from '@ant-design/icons';
8 | import { ProfileContext } from '../../context/profileContext';
9 | import { saveLinks } from '../../api';
10 |
11 | const linkRegex =
12 | /^(http(s):\/\/.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/;
13 |
14 | const linkRule = {
15 | pattern: linkRegex,
16 | message: 'Provide a valid link (starting with https://)!'
17 | };
18 |
19 | const LinkLabel = React.memo(({ icon, label, iconColor }) => {
20 | return (
21 |
22 |
{icon}
23 | {label}
24 |
25 | );
26 | });
27 |
28 | const Index = () => {
29 | const profileData = useContext(ProfileContext);
30 |
31 | const onSubmitForm = async (data) => {
32 | try {
33 | profileData.setLinks({ ...data });
34 | const { userId } = profileData;
35 | const userData = await saveLinks({
36 | userId,
37 | links: data
38 | });
39 | profileData.setUserId(userData.id);
40 | profileData.setLinks(userData.links);
41 | message.success('Data saved successfully!');
42 | } catch (e) {
43 | message.error(e.message);
44 | }
45 | };
46 |
47 | const { links } = profileData;
48 |
49 | return (
50 | } label="Github" />}
67 | name="github"
68 | rules={[linkRule]}
69 | >
70 |
71 |
72 | }
76 | label="YouTube"
77 | iconColor="red"
78 | />
79 | }
80 | rules={[linkRule]}
81 | name="youtube"
82 | >
83 |
84 |
85 | }
89 | label="LinkedIn"
90 | iconColor="#0a66c2"
91 | />
92 | }
93 | name="linkedin"
94 | rules={[linkRule]}
95 | >
96 |
97 |
98 |
103 |
104 | Submit
105 |
106 |
107 |
108 | );
109 | };
110 |
111 | export default Index;
112 |
--------------------------------------------------------------------------------
/src/components/AddProfileImage/index.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { PlusOutlined } from '@ant-design/icons';
3 | import { Modal, Upload } from 'antd';
4 | const getBase64 = (file) =>
5 | new Promise((resolve, reject) => {
6 | const reader = new FileReader();
7 | reader.readAsDataURL(file);
8 | reader.onload = () => resolve(reader.result);
9 | reader.onerror = (error) => reject(error);
10 | });
11 | const AddProfileImage = ({ imgURL, onUploadImg }) => {
12 | const [previewOpen, setPreviewOpen] = useState(false);
13 | const [previewImage, setPreviewImage] = useState('');
14 | const [previewTitle, setPreviewTitle] = useState('');
15 | const [fileList, setFileList] = useState(
16 | imgURL
17 | ? [
18 | {
19 | uid: '-1',
20 | name: 'image.png',
21 | url: imgURL,
22 | status: 'done'
23 | }
24 | ]
25 | : []
26 | );
27 | const handleCancel = () => setPreviewOpen(false);
28 | const handlePreview = async (file) => {
29 | if (!file.url && !file.preview) {
30 | file.preview = await getBase64(file.originFileObj);
31 | }
32 | setPreviewImage(file.url || file.preview);
33 | setPreviewOpen(true);
34 | setPreviewTitle(
35 | file.name || file.url.substring(file.url.lastIndexOf('/') + 1)
36 | );
37 | };
38 | const handleChange = ({ fileList: newFileList }) => setFileList(newFileList);
39 | const uploadButton = (
40 |
41 |
42 |
47 | Upload Profile Image
48 |
49 |
50 | );
51 | return (
52 |
53 |
61 | {fileList.length >= 1 ? null : uploadButton}
62 |
63 |
69 |
76 |
77 |
78 | );
79 | };
80 | export default React.memo(AddProfileImage);
81 |
--------------------------------------------------------------------------------
/src/components/AppContent/AppContent.module.css:
--------------------------------------------------------------------------------
1 | .app_content {
2 | background-color: aliceblue;
3 | padding: 20px;
4 | margin-top: 20px;
5 | }
--------------------------------------------------------------------------------
/src/components/AppContent/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import classes from './AppContent.module.css';
3 | import { Row } from 'antd';
4 | import { Outlet } from 'react-router-dom';
5 |
6 | const AppContent = () => {
7 | return (
8 |
9 |
10 |
11 | );
12 | };
13 |
14 | export default AppContent;
15 |
--------------------------------------------------------------------------------
/src/components/AppHeader/AppHeader.module.css:
--------------------------------------------------------------------------------
1 | .app_header {
2 | background-color: aliceblue;
3 | padding: 20px;
4 | }
5 |
6 | .active_route {
7 | color: #1677ff;
8 | border-bottom: #008eff 3px solid;
9 | padding-bottom: 10px;
10 | }
11 |
12 | .inactive_route {
13 | color: #000;
14 | }
--------------------------------------------------------------------------------
/src/components/AppHeader/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Row, Space } from 'antd';
3 | import classes from './AppHeader.module.css';
4 | import { NavLink } from 'react-router-dom';
5 |
6 | const AppHeader = () => {
7 | return (
8 |
9 |
10 | Dabot
11 |
12 |
13 |
15 | navData.isActive ? classes.active_route : classes.inactive_route
16 | }
17 | to="add-links"
18 | >
19 | Add Links
20 |
21 |
23 | navData.isActive ? classes.active_route : classes.inactive_route
24 | }
25 | to="profile-details"
26 | >
27 | Profile Details
28 |
29 |
30 |
31 |
33 | navData.isActive ? classes.active_route : classes.inactive_route
34 | }
35 | to="view-profile"
36 | >
37 | View Profile
38 |
39 |
40 |
41 | );
42 | };
43 |
44 | export default AppHeader;
45 |
--------------------------------------------------------------------------------
/src/components/AppLayout/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Col, Row } from 'antd';
3 | import AppHeader from '../AppHeader';
4 | import AppContent from '../AppContent';
5 |
6 | const AppLayout = () => {
7 | return (
8 |
9 |
10 |
11 |
12 |
13 |
14 | );
15 | };
16 |
17 | export default AppLayout;
18 |
--------------------------------------------------------------------------------
/src/components/EditProfileForm/index.js:
--------------------------------------------------------------------------------
1 | import React, { useCallback, useContext } from 'react';
2 | import { Button, Form, Input, message } from 'antd';
3 | import { ProfileContext } from '../../context/profileContext';
4 | import { saveProfileInfo, uploadProfileImage } from '../../api';
5 | import AddProfileImage from '../AddProfileImage';
6 |
7 | const EditProfileForm = () => {
8 | const profileData = useContext(ProfileContext);
9 |
10 | const onUploadImage = useCallback(async (data) => {
11 | try {
12 | const imageURL = await uploadProfileImage(profileData.userId, data);
13 | profileData.setProfileImgURL(imageURL);
14 | message.warning('Press submit to save the uploaded image!');
15 | } catch (e) {
16 | message.error(e.message);
17 | }
18 | return false;
19 | }, []);
20 |
21 | const onSubmitForm = async (data) => {
22 | try {
23 | const { firstName, lastName, email } = data;
24 | const { userId } = profileData;
25 | const userData = await saveProfileInfo({
26 | userId,
27 | firstName,
28 | lastName,
29 | email,
30 | profileImgURL: profileData.profileImgURL
31 | });
32 | profileData.setFirstName(userData.firstName);
33 | profileData.setLastName(userData.lastName);
34 | profileData.setEmail(userData.email);
35 | profileData.setUserId(userData.id);
36 | message.success('Data saved successfully!');
37 | } catch (e) {
38 | message.error(e.message);
39 | }
40 | };
41 |
42 | const { firstName, lastName, email } = profileData;
43 |
44 | return (
45 | <>
46 |
59 |
84 |
85 |
86 |
87 |
97 |
98 |
99 |
100 |
114 |
115 |
116 |
117 |
122 |
123 | Submit
124 |
125 |
126 |
127 | >
128 | );
129 | };
130 |
131 | export default React.memo(EditProfileForm);
132 |
--------------------------------------------------------------------------------
/src/components/ProfileBox/ProfileBox.module.css:
--------------------------------------------------------------------------------
1 | .profile_box {
2 | display: flex;
3 | flex-direction: column;
4 | justify-content: start;
5 | align-items: center;
6 | gap: 10px;
7 | width: 100%;
8 | min-height: 50vh;
9 | }
--------------------------------------------------------------------------------
/src/components/ProfileBox/index.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import classes from './ProfileBox.module.css';
3 | import { ProfileContext } from '../../context/profileContext';
4 | import { Avatar } from 'antd';
5 | import {
6 | GithubOutlined,
7 | LinkedinFilled,
8 | UserOutlined,
9 | YoutubeFilled
10 | } from '@ant-design/icons';
11 |
12 | const UserLink = React.memo(({ link, linkColor, icon, linkText }) => {
13 | return (
14 | window.open(`${link}`, '_blank')}
28 | >
29 |
37 | {icon}
38 |
39 |
{linkText}
40 |
41 | );
42 | });
43 |
44 | const ProfileBox = () => {
45 | const profileData = useContext(ProfileContext);
46 |
47 | return (
48 |
49 |
}
52 | src={profileData.profileImgURL}
53 | />
54 |
55 |
56 | {profileData.firstName} {profileData.lastName}
57 |
58 |
{profileData.email}
59 |
60 | {profileData?.links?.github ? (
61 |
}
63 | linkText="Github"
64 | linkColor="black"
65 | link={profileData.links.github}
66 | />
67 | ) : (
68 | ''
69 | )}
70 | {profileData?.links?.youtube ? (
71 |
}
73 | linkText="YouTube"
74 | linkColor="red"
75 | link={profileData.links.youtube}
76 | />
77 | ) : (
78 | ''
79 | )}
80 | {profileData?.links?.linkedin ? (
81 |
}
83 | linkText="LinkedIn"
84 | linkColor="#0a66c2"
85 | link={profileData.links.linkedin}
86 | />
87 | ) : (
88 | ''
89 | )}
90 |
91 | );
92 | };
93 |
94 | export default React.memo(ProfileBox);
95 |
--------------------------------------------------------------------------------
/src/context/profileContext.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 |
3 | export const ProfileContext = React.createContext({
4 | userId: null,
5 | firstName: '',
6 | lastName: '',
7 | email: '',
8 | links: {},
9 | profileImgURL: '',
10 | setProfileImgURL: (profileImgURL) => {},
11 | setFirstName: (firstName) => {},
12 | setLastName: (lastName) => {},
13 | setEmail: (email) => {},
14 | setLinks: (links) => {},
15 | setUserId: (userId) => {}
16 | });
17 |
18 | const ProfileContextProvider = ({ children }) => {
19 | const [firstName, setFirstName] = useState('');
20 | const [lastName, setLastName] = useState('');
21 | const [email, setEmail] = useState('');
22 | const [userId, setUserId] = useState(null);
23 | const [links, setLinks] = useState({});
24 | const [profileImgURL, setProfileImgURL] = useState('');
25 |
26 | return (
27 |
43 | {children}
44 |
45 | );
46 | };
47 |
48 | export default ProfileContextProvider;
49 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbasikov/task-fe/7cd387a6ace0de5b06effad0b5b1e277e236ce0d/src/index.css
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 | import 'antd/dist/reset.css';
7 |
8 | const root = ReactDOM.createRoot(document.getElementById('root'));
9 | root.render(
10 |
11 |
12 |
13 | );
14 |
15 | // If you want to start measuring performance in your app, pass a function
16 | // to log results (for example: reportWebVitals(console.log))
17 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18 | reportWebVitals();
19 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/pages/AddLinks.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react';
2 | import { Col, Row } from 'antd';
3 | import ProfileBox from '../components/ProfileBox';
4 | import AddLinksForm from '../components/AddLinksForm';
5 |
6 | const columnsStyling = {
7 | justifyContent: 'center',
8 | backgroundColor: '#fff',
9 | padding: 30,
10 | borderRadius: 10
11 | };
12 |
13 | const AddLinks = () => {
14 | const [showProfile, setShowProfile] = useState(window.innerWidth > 767);
15 |
16 | useEffect(() => {
17 | const eventListener = () => {
18 | setShowProfile(window.innerWidth > 767);
19 | };
20 | window.addEventListener('resize', eventListener);
21 | return () => {
22 | window.removeEventListener('resize', eventListener);
23 | };
24 | }, []);
25 |
26 | return (
27 |
28 | {showProfile ? (
29 |
41 |
42 |
43 | ) : (
44 | ''
45 | )}
46 |
47 | Add Links
48 | Add your links here.
49 |
50 |
51 |
52 | );
53 | };
54 | export default AddLinks;
55 |
--------------------------------------------------------------------------------
/src/pages/ProfileDetails.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react';
2 | import { Col, Row } from 'antd';
3 | import ProfileBox from '../components/ProfileBox';
4 | import EditProfileForm from '../components/EditProfileForm';
5 |
6 | const columnsStyling = {
7 | justifyContent: 'center',
8 | backgroundColor: '#fff',
9 | padding: 30,
10 | borderRadius: 10
11 | };
12 |
13 | const ProfileDetails = () => {
14 | const [showProfile, setShowProfile] = useState(window.innerWidth > 767);
15 |
16 | useEffect(() => {
17 | const eventListener = () => {
18 | setShowProfile(window.innerWidth > 767);
19 | };
20 | window.addEventListener('resize', eventListener);
21 | return () => {
22 | window.removeEventListener('resize', eventListener);
23 | };
24 | }, []);
25 |
26 | return (
27 |
28 | {showProfile ? (
29 |
41 |
42 |
43 | ) : (
44 | ''
45 | )}
46 |
47 | Profile Details
48 | Add your profile info here.
49 |
50 |
51 |
52 | );
53 | };
54 | export default ProfileDetails;
55 |
--------------------------------------------------------------------------------
/src/pages/SharedProfile.js:
--------------------------------------------------------------------------------
1 | import React, { useContext, useEffect, useState } from 'react';
2 | import { useNavigate, useParams } from 'react-router-dom';
3 | import { message } from 'antd';
4 | import { ProfileContext } from '../context/profileContext';
5 | import { getUserData } from '../api';
6 | import ProfileBox from '../components/ProfileBox';
7 |
8 | const SharedProfile = () => {
9 | const [loading, setLoading] = useState(true);
10 | const profileData = useContext(ProfileContext);
11 |
12 | const { token } = useParams();
13 | const navigate = useNavigate();
14 |
15 | const loadUserData = async (token) => {
16 | setLoading(true);
17 | try {
18 | const userData = await getUserData(token);
19 | if (!userData) {
20 | return navigate('/page-not-found', { replace: true });
21 | }
22 | profileData.setLinks(userData.links);
23 | profileData.setFirstName(userData.firstName);
24 | profileData.setLastName(userData.lastName);
25 | profileData.setEmail(userData.email);
26 | profileData.setProfileImgURL(userData.profileImgURL);
27 | } catch (e) {
28 | message.error(e.message);
29 | } finally {
30 | setLoading(false);
31 | }
32 | };
33 |
34 | useEffect(() => {
35 | loadUserData(token).then(() => {});
36 | }, [token]);
37 | return loading ? (
38 | Loading...
39 | ) : (
40 |
51 |
{profileData.firstName}'s Shared Profile
52 |
53 |
54 | );
55 | };
56 |
57 | export default SharedProfile;
58 |
--------------------------------------------------------------------------------
/src/pages/ViewProfile.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import { Button, Col, message, Row } from 'antd';
3 | import ProfileBox from '../components/ProfileBox';
4 | import { LinkOutlined } from '@ant-design/icons';
5 | import { ProfileContext } from '../context/profileContext';
6 | import { getShareableToken } from '../api';
7 |
8 | const columnsStyling = {
9 | justifyContent: 'center',
10 | backgroundColor: '#fff',
11 | padding: 30,
12 | borderRadius: 10
13 | };
14 |
15 | const ViewProfile = () => {
16 | const profileData = useContext(ProfileContext);
17 |
18 | const onShareProfile = async () => {
19 | try {
20 | if (
21 | !profileData.firstName &&
22 | !profileData.lastName &&
23 | !profileData.email
24 | ) {
25 | await message.error('Profile info not submitted yet!');
26 | return;
27 | }
28 | const shareableToken = await getShareableToken(profileData.userId);
29 | await navigator.clipboard.writeText(
30 | `${process.env.REACT_APP_FE_URL}/shared-profile/${shareableToken}`
31 | );
32 | message.success('Link copied to the clipboard!');
33 | message.info('Anybody with the link will be able to view the profile.');
34 | } catch (e) {
35 | await message.error(e.message);
36 | }
37 | };
38 |
39 | return (
40 | <>
41 |
42 | } onClick={onShareProfile}>
43 | Get Profile Link
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | >
52 | );
53 | };
54 | export default ViewProfile;
55 |
--------------------------------------------------------------------------------
/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------