Merge pull request #117 from EETagent/admin_create_error

This commit is contained in:
Vojtěch Jungmann 2023-01-02 22:26:12 +01:00 committed by GitHub
commit 1611e93ef1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View file

@ -13,7 +13,7 @@ export const apiLogin = async (data: AdminLogin): Promise<number> => {
try {
await axios.post(API_URL + '/admin/login', data, { withCredentials: true });
return data.adminId;
} catch (e: any) {
} catch (e) {
throw errorHandler(e, 'Login failed');
}
};
@ -24,7 +24,7 @@ export const apiCreateCandidate = async (data: CreateCandidate): Promise<CreateC
try {
const res = await axios.post(API_URL + '/admin/create', data, { withCredentials: true });
return res.data;
} catch (e: any) {
} catch (e) {
throw errorHandler(e, 'Candidate creation failed');
}
};
@ -48,7 +48,7 @@ export const apiResetCandidatePassword = async (id: number): Promise<CreateCandi
{ withCredentials: true }
);
return res.data;
} catch (e: any) {
} catch (e) {
throw errorHandler(e, 'Candidate creation failed');
}
};
@ -60,7 +60,7 @@ export const apiGetCandidatePortfolio = async (id: number): Promise<Blob> => {
credentials: 'include'
});
return await res.blob();
} catch (e: any) {
} catch (e) {
throw errorHandler(e, 'Candidate portfolio failed');
}
};

View file

@ -1,10 +1,11 @@
<script lang="ts">
import type { ApiError } from '$lib/@api';
import { apiCreateCandidate } from '$lib/@api/admin';
import type { CreateCandidate, CreateCandidateLogin } from '$lib/stores/candidate';
import { createEventDispatcher } from 'svelte';
import Modal from '../Modal.svelte';
import IdField from '../textfield/IdField.svelte';
import NumberField from '../textfield/NumberField.svelte';
import Modal from '../../Modal.svelte';
import IdField from '../../textfield/IdField.svelte';
import NumberField from '../../textfield/NumberField.svelte';
let isOpened = true;
@ -13,6 +14,8 @@
let login: CreateCandidateLogin;
let error: string = '';
const dispatch = createEventDispatcher();
const createCandidate = async () => {
@ -23,8 +26,9 @@
try {
login = await apiCreateCandidate(data);
dispatch('created');
} catch (e) {
console.log(e);
} catch (e: unknown) {
console.error(e);
error = (e as ApiError).msg;
}
};
@ -42,6 +46,11 @@
<h1 class="text-sspsBlue text-3xl font-semibold">{login.password}</h1>
{:else}
<h1 class="text-sspsBlue text-3xl font-semibold">Registrace nového uchazeče</h1>
{#if error}
<div class="my-2 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
<span class="block sm:inline">{error}</span>
</div>
{/if}
<h3 class="my-4">Evidenčni číslo přihlášky</h3>
<NumberField bind:value={applicationId} />
<h3 class="my-4">Rodné číslo</h3>

View file

@ -3,7 +3,7 @@
import Home from '$lib/components/icons/Home.svelte';
import TextField from '$lib/components/textfield/TextField.svelte';
import type { CandidatePreview } from '$lib/stores/candidate';
import CreateCandidateModal from '$lib/components/admin/CreateCandidateModal.svelte';
import CreateCandidateModal from '$lib/components/admin/modal/CreateCandidateModal.svelte';
import Fuse from 'fuse.js';
import type { PageServerData } from './$types';
import Table from '$lib/components/admin/table/Table.svelte';