2022-05-21 02:23:55 -05:00
|
|
|
type AdminRegistrationResult = Promise<{
|
2022-06-27 15:13:07 -05:00
|
|
|
error?: string;
|
|
|
|
success?: string;
|
|
|
|
user?: {
|
|
|
|
email: string;
|
|
|
|
};
|
|
|
|
}>;
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
type LoginResult = Promise<{
|
2022-06-27 15:13:07 -05:00
|
|
|
error?: string;
|
|
|
|
success?: string;
|
|
|
|
user?: {
|
|
|
|
accessToken: string;
|
|
|
|
firstName: string;
|
|
|
|
lastName: string;
|
|
|
|
isAdmin: boolean;
|
|
|
|
id: string;
|
|
|
|
email: string;
|
|
|
|
shouldChangePassword: boolean;
|
|
|
|
};
|
|
|
|
}>;
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
type UpdateResult = Promise<{
|
2022-06-27 15:13:07 -05:00
|
|
|
error?: string;
|
|
|
|
success?: string;
|
|
|
|
user?: {
|
|
|
|
accessToken: string;
|
|
|
|
firstName: string;
|
|
|
|
lastName: string;
|
|
|
|
isAdmin: boolean;
|
|
|
|
id: string;
|
|
|
|
email: string;
|
|
|
|
};
|
|
|
|
}>;
|
2022-05-21 02:23:55 -05:00
|
|
|
|
|
|
|
export async function sendRegistrationForm(form: HTMLFormElement): AdminRegistrationResult {
|
2022-06-27 15:13:07 -05:00
|
|
|
const response = await fetch(form.action, {
|
|
|
|
method: form.method,
|
|
|
|
body: new FormData(form),
|
|
|
|
headers: { accept: 'application/json' },
|
|
|
|
});
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2022-06-27 15:13:07 -05:00
|
|
|
return await response.json();
|
2022-05-21 02:23:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function sendLoginForm(form: HTMLFormElement): LoginResult {
|
2022-06-27 15:13:07 -05:00
|
|
|
const response = await fetch(form.action, {
|
|
|
|
method: form.method,
|
|
|
|
body: new FormData(form),
|
|
|
|
headers: { accept: 'application/json' },
|
|
|
|
});
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2022-06-27 15:13:07 -05:00
|
|
|
return await response.json();
|
2022-05-21 02:23:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function sendUpdateForm(form: HTMLFormElement): UpdateResult {
|
2022-06-27 15:13:07 -05:00
|
|
|
const response = await fetch(form.action, {
|
|
|
|
method: form.method,
|
|
|
|
body: new FormData(form),
|
|
|
|
headers: { accept: 'application/json' },
|
|
|
|
});
|
2022-05-21 02:23:55 -05:00
|
|
|
|
2022-06-27 15:13:07 -05:00
|
|
|
return await response.json();
|
2022-05-21 02:23:55 -05:00
|
|
|
}
|