2021-07-02 16:02:47 +03:00
|
|
|
export const fetchProfile = async (link, index) => {
|
2021-07-21 14:40:06 +03:00
|
|
|
try {
|
2021-08-04 17:27:09 +03:00
|
|
|
const response = await fetch(`${link}${index}`, {
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
|
|
|
|
}
|
|
|
|
})
|
2021-08-04 13:04:05 +03:00
|
|
|
let data = await response.json()
|
2021-06-28 17:57:28 +03:00
|
|
|
|
2021-08-04 13:04:05 +03:00
|
|
|
return data
|
2021-07-21 14:40:06 +03:00
|
|
|
} catch (error) {}
|
2021-08-04 13:04:05 +03:00
|
|
|
}
|
2021-06-29 17:58:15 +03:00
|
|
|
|
|
|
|
export const fetchSkills = async (link) => {
|
2021-07-21 14:40:06 +03:00
|
|
|
try {
|
2021-08-04 17:27:09 +03:00
|
|
|
const response = await fetch(link, {
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
|
|
|
|
}
|
|
|
|
})
|
2021-08-04 13:04:05 +03:00
|
|
|
let data = await response.json()
|
2021-06-29 17:58:15 +03:00
|
|
|
|
2021-08-04 13:04:05 +03:00
|
|
|
return data
|
2021-07-21 14:40:06 +03:00
|
|
|
} catch (error) {}
|
2021-08-04 13:04:05 +03:00
|
|
|
}
|
2021-07-03 17:37:30 +03:00
|
|
|
|
|
|
|
export const fetchItemsForId = async (link, id) => {
|
2021-07-21 14:40:06 +03:00
|
|
|
try {
|
2021-08-04 17:27:09 +03:00
|
|
|
const response = await fetch(`${link}${id}`, {
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
|
|
|
|
}
|
|
|
|
})
|
2021-08-04 13:04:05 +03:00
|
|
|
let data = await response.json()
|
2021-07-03 17:37:30 +03:00
|
|
|
|
2021-08-04 13:04:05 +03:00
|
|
|
return data
|
2021-07-21 14:40:06 +03:00
|
|
|
} catch (error) {}
|
2021-08-04 13:04:05 +03:00
|
|
|
}
|
2021-07-03 17:37:30 +03:00
|
|
|
|
|
|
|
export const fetchForm = async (link, info) => {
|
2021-07-21 14:40:06 +03:00
|
|
|
try {
|
|
|
|
const response = await fetch(link, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2021-08-04 17:27:09 +03:00
|
|
|
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`,
|
2021-08-04 13:04:05 +03:00
|
|
|
'Content-Type': 'multipart/form-data'
|
2021-07-21 14:40:06 +03:00
|
|
|
},
|
2021-08-04 13:04:05 +03:00
|
|
|
body: info
|
|
|
|
})
|
2021-07-03 17:37:30 +03:00
|
|
|
|
2021-08-04 13:04:05 +03:00
|
|
|
return response
|
2021-07-21 14:40:06 +03:00
|
|
|
} catch (error) {}
|
2021-08-04 13:04:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchAuth = async ({ username, password, dispatch }) => {
|
2021-08-04 17:27:09 +03:00
|
|
|
const baseURL = process.env.REACT_APP_BASE_URL;
|
|
|
|
const apiURL = process.env.REACT_APP_API_URL;
|
2021-08-04 13:04:05 +03:00
|
|
|
try {
|
|
|
|
const response = await fetch(
|
2021-08-04 17:27:09 +03:00
|
|
|
`${apiURL}/api/user/login`,
|
2021-08-04 13:04:05 +03:00
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
2021-08-04 17:27:09 +03:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Origin': `${baseURL}`,
|
2021-08-04 13:04:05 +03:00
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
username,
|
|
|
|
password
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if(!response.ok) {
|
|
|
|
return response.statusText;
|
|
|
|
}
|
|
|
|
|
|
|
|
response
|
|
|
|
.json()
|
|
|
|
.then((resJSON) => {
|
|
|
|
localStorage.setItem('auth_token', resJSON.access_token)
|
|
|
|
localStorage.setItem('access_token_expired_at', resJSON.access_token_expired_at)
|
|
|
|
dispatch();
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error occured: ', error)
|
|
|
|
}
|
|
|
|
}
|