mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: post candidate data
This commit is contained in:
parent
214aa7ace8
commit
c78529b9bb
2 changed files with 25 additions and 27 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue