mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 05:51:56 +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> => {
|
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
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
data[key] = DOMPurify.sanitize(data[key]);
|
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 {
|
try {
|
||||||
const res = await axios.post(API_URL + '/candidate/details', data, { withCredentials: true });
|
const res = await axios.post(API_URL + '/candidate/details', data, { withCredentials: true });
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
import NameField from '$lib/components/textfield/NameField.svelte';
|
import NameField from '$lib/components/textfield/NameField.svelte';
|
||||||
import TelephoneField from '$lib/components/textfield/TelephoneField.svelte';
|
import TelephoneField from '$lib/components/textfield/TelephoneField.svelte';
|
||||||
import TextField from '$lib/components/textfield/TextField.svelte';
|
import TextField from '$lib/components/textfield/TextField.svelte';
|
||||||
|
import type { CandidateData } from '$lib/stores/candidate';
|
||||||
|
|
||||||
import { createForm } from 'svelte-forms-lib';
|
import { createForm } from 'svelte-forms-lib';
|
||||||
import type { Writable } from 'svelte/store';
|
import type { Writable } from 'svelte/store';
|
||||||
|
|
@ -21,30 +22,7 @@
|
||||||
let pageIndex = 0;
|
let pageIndex = 0;
|
||||||
let pagesFilled = 0;
|
let pagesFilled = 0;
|
||||||
|
|
||||||
interface FormInterface
|
const formInitialValues = {
|
||||||
{
|
|
||||||
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 = {
|
|
||||||
candidate: {
|
candidate: {
|
||||||
name: '',
|
name: '',
|
||||||
surname: '',
|
surname: '',
|
||||||
|
|
@ -100,13 +78,25 @@
|
||||||
).required()
|
).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) {
|
if (pageIndex === pageCount) {
|
||||||
try {
|
try {
|
||||||
console.log('submit');
|
console.log('submit');
|
||||||
// @ts-ignore // love javascript
|
// @ts-ignore // love javascript
|
||||||
delete values.undefined;
|
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);
|
await apiFillDetails(values);
|
||||||
goto('/dashboard');
|
goto('/dashboard');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue