From ffd679a0a93d708e04e2353c855390c54d9751e0 Mon Sep 17 00:00:00 2001 From: kurpfish Date: Thu, 5 Aug 2021 16:44:49 +0300 Subject: [PATCH] redirect buttons and api url fixes --- package-lock.json | 8 ++++++++ package.json | 1 + src/api/index.js | 5 +++++ src/components/Auth/AuthForDevelopers.js | 6 +++++- src/components/Auth/AuthForDevelopers.module.css | 13 +++++++++++++ src/components/Auth/AuthForPartners.js | 6 +++++- src/components/Auth/AuthForPartners.module.css | 12 ++++++++++++ src/components/Candidate/Candidate.js | 2 +- src/components/Description/Description.js | 2 +- src/components/Form/Form.js | 2 +- src/components/Home/Home.js | 4 ++-- src/components/Outstaffing/Outstaffing.js | 2 +- src/components/Select/TagSelect.js | 2 +- src/server/server.js | 5 +++++ 14 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 src/api/index.js diff --git a/package-lock.json b/package-lock.json index 3b4d2ac1..26b95c25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3216,6 +3216,14 @@ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.2.1.tgz", "integrity": "sha512-evY7DN8qSIbsW2H/TWQ1bX3sXN1d4MNb5Vb4n7BzPuCwRHdkZ1H2eNLuSh73EoQqkGKUtju2G2HCcjCfhvZIAA==" }, + "axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", diff --git a/package.json b/package.json index 8abc5d7a..8ead7592 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@testing-library/jest-dom": "^5.12.0", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", + "axios": "^0.21.1", "bootstrap": "^4.6.0", "dotenv": "^10.0.0", "eslint": "^7.27.0", diff --git a/src/api/index.js b/src/api/index.js new file mode 100644 index 00000000..9f6886d7 --- /dev/null +++ b/src/api/index.js @@ -0,0 +1,5 @@ +import axios from 'axios'; + +export default axios.create({ + baseURL: process.env.REACT_APP_API_URL +}); \ No newline at end of file diff --git a/src/components/Auth/AuthForDevelopers.js b/src/components/Auth/AuthForDevelopers.js index ce94de8b..a578dfd7 100644 --- a/src/components/Auth/AuthForDevelopers.js +++ b/src/components/Auth/AuthForDevelopers.js @@ -16,7 +16,7 @@ import { fetchAuth } from '../../server/server' import { useSelector } from 'react-redux' import { selectAuth } from '../../redux/outstaffingSlice'; -import { Redirect } from 'react-router-dom'; +import { Redirect, Link } from 'react-router-dom'; const AuthForDevelopers = () => { const dispatch = useDispatch() @@ -77,6 +77,10 @@ const AuthForDevelopers = () => { > Войти + + diff --git a/src/components/Auth/AuthForDevelopers.module.css b/src/components/Auth/AuthForDevelopers.module.css index 63d34e32..f55c227c 100644 --- a/src/components/Auth/AuthForDevelopers.module.css +++ b/src/components/Auth/AuthForDevelopers.module.css @@ -399,3 +399,16 @@ line-height: normal; margin-left: 24px; } + +.auth__link { + display: block; + margin-top: 1.3rem; +} + + +.auth__link a { + display: block; + width: 100%; + height: 100%; + color: #fff; +} \ No newline at end of file diff --git a/src/components/Auth/AuthForPartners.js b/src/components/Auth/AuthForPartners.js index 20d93134..dfab8a54 100644 --- a/src/components/Auth/AuthForPartners.js +++ b/src/components/Auth/AuthForPartners.js @@ -16,7 +16,7 @@ import { fetchAuth } from '../../server/server' import { useSelector } from 'react-redux' import { selectAuth } from '../../redux/outstaffingSlice'; -import { Redirect } from 'react-router-dom'; +import { Redirect, Link } from 'react-router-dom'; const AuthForPartners = () => { const dispatch = useDispatch() @@ -70,6 +70,10 @@ const AuthForPartners = () => { }> Войти + + diff --git a/src/components/Auth/AuthForPartners.module.css b/src/components/Auth/AuthForPartners.module.css index f7cb98fb..db43afbe 100644 --- a/src/components/Auth/AuthForPartners.module.css +++ b/src/components/Auth/AuthForPartners.module.css @@ -400,3 +400,15 @@ line-height: normal; margin-left: 24px; } + +.auth__link { + display: block; + margin-top: 1.3rem; +} + +.auth__link a { + display: block; + width: 100%; + height: 100%; + color: #fff; +} \ No newline at end of file diff --git a/src/components/Candidate/Candidate.js b/src/components/Candidate/Candidate.js index 8e8eee7c..9a9f4586 100644 --- a/src/components/Candidate/Candidate.js +++ b/src/components/Candidate/Candidate.js @@ -18,7 +18,7 @@ const Candidate = () => { const dispatch = useDispatch(); useEffect(() => { - fetchItemsForId('https://guild.craft-group.xyz/api/profile/', Number(candidateId)).then((el) => + fetchItemsForId(`${process.env.REACT_APP_API_URL}/api/profile/`, Number(candidateId)).then((el) => dispatch(currentCandidate(el)) ); }, [dispatch, candidateId]); diff --git a/src/components/Description/Description.js b/src/components/Description/Description.js index c956db78..2c77c38b 100644 --- a/src/components/Description/Description.js +++ b/src/components/Description/Description.js @@ -14,7 +14,7 @@ const Description = ({ onLoadMore }) => { const [allCandidates, getAllCandidates] = useState([]); useEffect(() => { - fetchProfile('https://guild.craft-group.xyz/api/profile?limit=', 1000).then((p) => getAllCandidates(p)); + fetchProfile(`${process.env.REACT_APP_API_URL}/api/profile?limit=`, 1000).then((p) => getAllCandidates(p)); }, []); return ( diff --git a/src/components/Form/Form.js b/src/components/Form/Form.js index e3cd7787..10765bc0 100644 --- a/src/components/Form/Form.js +++ b/src/components/Form/Form.js @@ -30,7 +30,7 @@ const Form = () => { formData.append('phone', data.phone); formData.append('comment', data.comment); - fetchForm('https://guild.craft-group.xyz/api/profile/add-to-interview', formData); + fetchForm(`${process.env.REACT_APP_API_URL}/api/profile/add-to-interview`, formData); }; const goBack = () => { diff --git a/src/components/Home/Home.js b/src/components/Home/Home.js index 52d1f491..84f7c31d 100644 --- a/src/components/Home/Home.js +++ b/src/components/Home/Home.js @@ -11,11 +11,11 @@ const Home = () => { const dispatch = useDispatch(); useEffect(() => { - fetchProfile('https://guild.craft-group.xyz/api/profile?limit=', index).then((profileArr) => + fetchProfile(`${process.env.REACT_APP_API_URL}/api/profile?limit=`, index).then((profileArr) => dispatch(profiles(profileArr)) ); - fetchSkills('https://guild.craft-group.xyz/api/skills/skills-on-main-page').then((skills) => { + fetchSkills(`${process.env.REACT_APP_API_URL}/api/skills/skills-on-main-page`).then((skills) => { const keys = Object.keys(skills); const values = Object.values(skills); diff --git a/src/components/Outstaffing/Outstaffing.js b/src/components/Outstaffing/Outstaffing.js index 2c1916d7..47dd8e74 100644 --- a/src/components/Outstaffing/Outstaffing.js +++ b/src/components/Outstaffing/Outstaffing.js @@ -28,7 +28,7 @@ const Outstaffing = () => {
tag.name === 'skills_front')} + dataTags={tagsArr && tagsArr.flat().filter((tag) => tag.name === 'skills_front')} img={front} header="Фронтенд" /> diff --git a/src/components/Select/TagSelect.js b/src/components/Select/TagSelect.js index 85fd2a94..a78075b4 100644 --- a/src/components/Select/TagSelect.js +++ b/src/components/Select/TagSelect.js @@ -15,7 +15,7 @@ const TagSelect = () => { const handleSubmit = () => { const filterItemsId = itemsArr.map((item) => item.id).join(); - fetchItemsForId(`https://guild.craft-group.xyz/api/profile?skills=`, filterItemsId).then((el) => + fetchItemsForId(`${process.env.REACT_APP_API_URL}/api/profile?skills=`, filterItemsId).then((el) => dispatch(filteredCandidates(el)) ); diff --git a/src/server/server.js b/src/server/server.js index d1ba75af..8effa413 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -2,6 +2,7 @@ export const fetchProfile = async (link, index) => { try { const response = await fetch(`${link}${index}`, { headers: { + 'Access-Control-Request-Headers': 'authorization', 'Authorization': `Bearer ${localStorage.getItem('auth_token')}`, 'Origin': `${process.env.REACT_APP_BASE_URL}`, } @@ -16,6 +17,7 @@ export const fetchSkills = async (link) => { try { const response = await fetch(link, { headers: { + 'Access-Control-Request-Headers': 'authorization', 'Authorization': `Bearer ${localStorage.getItem('auth_token')}`, 'Origin': `${process.env.REACT_APP_BASE_URL}`, } @@ -27,9 +29,11 @@ export const fetchSkills = async (link) => { } export const fetchItemsForId = async (link, id) => { + console.log(`Bearer ${localStorage.getItem('auth_token')}`); try { const response = await fetch(`${link}${id}`, { headers: { + // 'Access-Control-Request-Headers': 'authorization', 'Authorization': `Bearer ${localStorage.getItem('auth_token')}`, 'Origin': `${process.env.REACT_APP_BASE_URL}`, } @@ -45,6 +49,7 @@ export const fetchForm = async (link, info) => { const response = await fetch(link, { method: 'POST', headers: { + 'Access-Control-Request-Headers': 'authorization', 'Authorization': `Bearer ${localStorage.getItem('auth_token')}`, 'Origin': `${process.env.REACT_APP_BASE_URL}`, 'Content-Type': 'multipart/form-data'