feat: post candidate data

This commit is contained in:
Sebastian Pravda 2022-12-06 17:42:38 +01:00
parent 214aa7ace8
commit c78529b9bb
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57
2 changed files with 25 additions and 27 deletions

View file

@ -79,11 +79,19 @@ export const apiLogin = async (data: CandidateLogin): Promise<number> => {
};
export const apiFillDetails = async (data: CandidateData): Promise<CandidateData> => {
Object.keys(data).forEach((key) => {
Object.keys(data.candidate).forEach((key) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
data[key] = DOMPurify.sanitize(data[key]);
});
data.parents.forEach((parent) => {
Object.keys(parent).forEach((key) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
parent[key] = DOMPurify.sanitize(parent[key]);
});
});
console.log(data);
try {
const res = await axios.post(API_URL + '/candidate/details', data, { withCredentials: true });
return res.data;

View file

@ -12,6 +12,7 @@
import NameField from '$lib/components/textfield/NameField.svelte';
import TelephoneField from '$lib/components/textfield/TelephoneField.svelte';
import TextField from '$lib/components/textfield/TextField.svelte';
import type { CandidateData } from '$lib/stores/candidate';
import { createForm } from 'svelte-forms-lib';
import type { Writable } from 'svelte/store';
@ -21,30 +22,7 @@
let pageIndex = 0;
let pagesFilled = 0;
interface FormInterface
{
candidate: {
name: string;
surname: string;
email: string;
telephone: string;
birthplace: string;
birthdate: string;
sex: string;
address: string;
citizenship: string;
personalIdNumber: string;
study: string;
}
parents: Array<{
name: string;
surname: string;
email: string;
telephone: string;
}>;
}
const formInitialValues: FormInterface = {
const formInitialValues = {
candidate: {
name: '',
surname: '',
@ -100,13 +78,25 @@
).required()
}),
onSubmit: async (values) => {
onSubmit: async (values: CandidateData) => {
console.log("page count: " + pageIndex);
console.log(values.candidate);
console.log(values.parents);
console.log(values);
if (pageIndex === pageCount) {
try {
console.log('submit');
// @ts-ignore // love javascript
delete values.undefined;
values.candidate.birthdate = '2000-01-01'; // TODO: reformat user typed date
// convert birthdate from dd.mm.yyyy to yyyy-mm-dd
let birthdate_formttted = values.candidate.birthdate!
.split('.')
.map((x) => x.padStart(2, '0'))
.reverse()
.join('-');
values.candidate.birthdate = birthdate_formttted;
await apiFillDetails(values);
goto('/dashboard');
} catch (e) {