Fixed file upload
This commit is contained in:
@@ -15,4 +15,5 @@ export interface User {
|
||||
role: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
profile_picture?: string;
|
||||
}
|
||||
|
||||
@@ -21,19 +21,23 @@ interface PostOptions {
|
||||
|
||||
export async function post(endpoint: string, body: any, options?: PostOptions): Promise<Response> {
|
||||
const url = `${baseURL}/${endpoint}`;
|
||||
const headers = options?.headers || {};
|
||||
let response;
|
||||
if (!options?.type || options.type === 'json') {
|
||||
body = JSON.stringify(body);
|
||||
headers['Content-Type'] = 'application/json';
|
||||
} else if (options.type === 'form') {
|
||||
headers['Content-Type'] = 'multipart/form-data';
|
||||
response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
} else {
|
||||
response = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body
|
||||
});
|
||||
}
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
credentials: 'include',
|
||||
body
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,13 @@ export default function Header() {
|
||||
if (response) {
|
||||
setRefreshId(refreshLoggedIn());
|
||||
setUser(response.user);
|
||||
getPicture().then((response) => {
|
||||
if (response) {
|
||||
setProfilePicture(response as File);
|
||||
}
|
||||
});
|
||||
if (response.user.profile_picture) {
|
||||
getPicture().then((response) => {
|
||||
if (response) {
|
||||
setProfilePicture(response as File);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -172,11 +174,13 @@ export default function Header() {
|
||||
toggle={toggle}
|
||||
setUser={(u) => {
|
||||
setUser(u);
|
||||
getPicture().then((response) => {
|
||||
if (response) {
|
||||
setProfilePicture(response as File);
|
||||
}
|
||||
});
|
||||
if (u.profile_picture) {
|
||||
getPicture().then((response) => {
|
||||
if (response) {
|
||||
setProfilePicture(response as File);
|
||||
}
|
||||
});
|
||||
}
|
||||
}}
|
||||
setRefreshId={setRefreshId}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user