mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-09 09:41:37 +00:00
refactor: remove stores no longer needed after SSR
This commit is contained in:
parent
fa8e109338
commit
8950f133bf
4 changed files with 6 additions and 74 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
import { apiFetchDetails, apiFillDetails, apiLogin, apiLogout } from "../@api/candidate";
|
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
import { browser } from "$app/environment";
|
|
||||||
|
|
||||||
export interface CandidateData {
|
export interface CandidateData {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
|
@ -26,66 +24,3 @@ export interface CandidateLogin {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const candidateData = writable<CandidateData>({});
|
export const candidateData = writable<CandidateData>({});
|
||||||
|
|
||||||
|
|
||||||
if (browser) {
|
|
||||||
const name = localStorage.getItem("name");
|
|
||||||
const surname = localStorage.getItem("surname");
|
|
||||||
const email = localStorage.getItem("email");
|
|
||||||
if (name && email && surname) {
|
|
||||||
candidateData.set({
|
|
||||||
name,
|
|
||||||
surname,
|
|
||||||
email
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
candidateData.subscribe((val) => {
|
|
||||||
if (browser) {
|
|
||||||
localStorage.setItem("name", val.name ?? "");
|
|
||||||
localStorage.setItem("surname", val.surname ?? "");
|
|
||||||
localStorage.setItem("email", val.email ?? "");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
export async function login(data: CandidateLogin) {
|
|
||||||
// TODO: handle errors
|
|
||||||
try {
|
|
||||||
const applicationId = await apiLogin(data); // TODO: set candidate data from response to store
|
|
||||||
console.log("login result: " + applicationId);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("login failed");
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function logout() {
|
|
||||||
// TOOD: handle errors
|
|
||||||
try {
|
|
||||||
await apiLogout();
|
|
||||||
candidateData.set({});
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fillDetails(data: CandidateData) {
|
|
||||||
try {
|
|
||||||
const res = await apiFillDetails(data);
|
|
||||||
candidateData.set(res);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetchDetails() {
|
|
||||||
try {
|
|
||||||
const res = await apiFetchDetails();
|
|
||||||
candidateData.set(res);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -18,7 +18,7 @@ export const submissionProgress = writable<SubmissionProgress>({});
|
||||||
|
|
||||||
export async function fetchSubmProgress() {
|
export async function fetchSubmProgress() {
|
||||||
try {
|
try {
|
||||||
let prog = await apiFetchSubmissionProgress();
|
const prog = await apiFetchSubmissionProgress();
|
||||||
submissionProgress.set(prog);
|
submissionProgress.set(prog);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
import { apiFillDetails } from '$lib/@api/candidate';
|
||||||
|
|
||||||
import Email from '$lib/components/icons/Email.svelte';
|
import Email from '$lib/components/icons/Email.svelte';
|
||||||
import Home from '$lib/components/icons/Home.svelte';
|
import Home from '$lib/components/icons/Home.svelte';
|
||||||
|
|
@ -10,13 +11,9 @@
|
||||||
import IdField from '$lib/components/textfield/IdField.svelte';
|
import IdField from '$lib/components/textfield/IdField.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 { fillDetails, candidateData, type CandidateData } from '$lib/stores/candidate';
|
|
||||||
|
|
||||||
import { createForm } from 'svelte-forms-lib';
|
import { createForm } from 'svelte-forms-lib';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { writable } from 'svelte/store';
|
|
||||||
|
|
||||||
let applicationValue = '';
|
|
||||||
|
|
||||||
const pageCount = 3;
|
const pageCount = 3;
|
||||||
let pageIndex = 0;
|
let pageIndex = 0;
|
||||||
|
|
@ -67,7 +64,7 @@
|
||||||
// @ts-ignore // love javascript
|
// @ts-ignore // love javascript
|
||||||
delete values.undefined;
|
delete values.undefined;
|
||||||
values.birthdate = '2000-01-01' // TODO: reformat user typed date
|
values.birthdate = '2000-01-01' // TODO: reformat user typed date
|
||||||
await fillDetails(values);
|
await apiFillDetails(values);
|
||||||
goto("/dashboard");
|
goto("/dashboard");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("error while submitting data: " + e);
|
console.error("error while submitting data: " + e);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
import woman from '$lib/assets/woman.png';
|
import woman from '$lib/assets/woman.png';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { login } from '$lib/stores/candidate';
|
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
import { apiLogin } from '$lib/@api/candidate';
|
||||||
|
|
||||||
|
|
||||||
let applicationId = Number($page.params.code);
|
let applicationId = Number($page.params.code);
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
try {
|
try {
|
||||||
await login({applicationId, password: codeValueMobile});
|
await apiLogin({applicationId, password: codeValueMobile});
|
||||||
goto("/dashboard");
|
goto("/dashboard");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue