Skip to content

Commit

Permalink
update id validation
Browse files Browse the repository at this point in the history
  • Loading branch information
birdpump committed Apr 5, 2024
1 parent f02eee2 commit 1f423ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/routes/(app)/register/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writable } from 'svelte/store';

export const registrationData = writable({});
export const studentId1 = writable()
export const studentId2 = writable()
export const singleLocker = writable(false)
export const studentId1 = writable();
export const studentId2 = writable();
export const singleLocker = writable(false);
2 changes: 1 addition & 1 deletion src/routes/(app)/register/views/Status.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="main" in:fade={{ delay: 0, duration: 700, easing: quartOut }}>
<div class="box">
<div class="box-cont">
<div class="box-header">Enabled Grade Levels</div>
<div class="box-header">Grades that can Register:</div>

<div class="stat-div">
<div class="stat-1-subcont-1">
Expand Down
38 changes: 20 additions & 18 deletions src/routes/(app)/register/views/View1.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import {createEventDispatcher} from "svelte";
import {fade, slide} from "svelte/transition";
import {slide} from "svelte/transition";
import {quartOut} from "svelte/easing";
import {validateID} from "$lib/services/app/mainApi.js";
import {studentId1, studentId2, singleLocker} from "../store.js";
import {singleLocker, studentId1, studentId2} from "../store.js";
const dispatch = createEventDispatcher();
Expand All @@ -21,20 +21,21 @@
async function login(event) {
event.preventDefault();
if ($singleLocker) {
try {
let response = await validateID(student1);
if (response.status === 400) {
const jsonResponse = await response.json();
input1.style.borderColor = "red";
input1.value = "";
input1.placeholder = "Invalid ID"; //todo this should get a message from the server
input1.placeholder = jsonResponse.error;
} else if (response.ok) {
studentId1.set(studentId1);
dispatch("message", {
data: await response.json(), //todo set this in the store
});
// dispatch("message", {
// data: await response.json(), //todo set this in the store
// });
}
} catch (error) {
input1.style.borderColor = "red";
Expand All @@ -43,20 +44,20 @@
}
} else {
//student 1
let responses = [];
let status = true;
if(student1 === student2) status = false;
if (student1 === student2) status = false;
try {
let response = await validateID(student1);
if (response.status === 400) {
const jsonResponse = await response.json();
status = false;
input1.style.borderColor = "red";
input1.value = "";
input1.placeholder = "Invalid ID"; //todo this should get a message from the server
input1.placeholder = jsonResponse.error; //todo this should get a message from the server
} else if (response.ok) {
studentId1.set(student1);
responses[0] = await response.json();
}
} catch (error) {
input1.style.borderColor = "red";
Expand All @@ -69,12 +70,13 @@
try {
let response = await validateID(student2);
if (response.status === 400) {
const jsonResponse = await response.json();
status = false;
input2.style.borderColor = "red";
input2.value = "";
input2.placeholder = "Invalid ID"; //todo this should get a message from the server
input2.placeholder = jsonResponse.error; //todo this should get a message from the server
} else if (response.ok) {
studentId2.set(student2);
responses[1] = await response.json();
}
} catch (error) {
input2.style.borderColor = "red";
Expand All @@ -85,9 +87,10 @@
//once both all good, send the response
if (status) {
dispatch("message", {
data: responses, //todo set this in the store
});
// dispatch("message", {
// data: responses, //todo set this in the store
// });
alert("all good");
}
}
Expand All @@ -110,7 +113,6 @@
<meta content="cvapps.net" name="author"/>
</svelte:head>


<style>
:root {
--text: #d6d6d6;
Expand Down Expand Up @@ -289,7 +291,7 @@
<div class="login-cont">
<div class="login-header">Register for a locker</div>

<form class="login-form" on:submit={login} on:keydown={handleKeyPress}>
<form class="login-form" on:keydown={handleKeyPress} on:submit={login}>
<label>Student 1</label>

<input
Expand Down

0 comments on commit 1f423ed

Please sign in to comment.