Skip to content

Commit

Permalink
added somewhat working registration
Browse files Browse the repository at this point in the history
  • Loading branch information
birdpump committed Apr 12, 2024
1 parent 2c82287 commit 1360251
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 56 deletions.
19 changes: 18 additions & 1 deletion src/lib/services/app/mainApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ export async function checkVerification(data){
return await fetch(`https://locker-api.cvapps.net/public/check-verification/${data}`, {
method: "get",
});
}
}

export async function fetchAvailableLockers(){
let response = await fetch(`http://locker-api.cvapps.net/public/available-lockers`, {
method: "get",
});

return await response.json();
}


export async function submitLockers(data){
return await fetch('https://locker-api.cvapps.net/public/register-locker', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
});
}
1 change: 1 addition & 0 deletions src/routes/(app)/register/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$: if($pageView === 1) selected = Selection;
$: if($pageView === 2) selected = View1;
$: if($pageView === 3) selected = View2;
$: if($pageView === 4) selected = Final;
Expand Down
46 changes: 12 additions & 34 deletions src/routes/(app)/register/views/Final.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,32 @@
import {writable} from "svelte/store";
import {slide} from "svelte/transition";
import {quartOut} from "svelte/easing";
import {singleLocker, studentId1, studentId2} from "../store.js";
import {submitLockers} from "$lib/services/app/mainApi.js";
import {singleLocker, studentId1, studentId2, selectedLocation} from "../store.js";
const studentStatusStore = writable({});
let buttonMessage = 'Check';
let studentsArr = [];
function next() {
//todo call check verify function
checkIDs();
// pageView.set(3);
}
async function checkIDs(){
if($singleLocker){
let response = await checkVerification($studentId1);
let json = await response.json();
studentStatusStore.set({student_1: json.verified});
if($studentStatusStore.student_1) console.log("one verified");
}else{
let response1 = await checkVerification($studentId1);
let response2 = await checkVerification($studentId2);
let json1 = await response1.json();
let json2 = await response2.json();
let buttonMessage = 'Submit';
studentStatusStore.set({student_1: json1.verified, student_2: json2.verified});
function next() {
studentsArr[0] = $studentId1;
studentsArr[1] = $studentId2; //todo account for single lockers
if($studentStatusStore.student_1 && $studentStatusStore.student_2) console.log("both verified");
let finalArr = {
"students": studentsArr,
"location": $selectedLocation,
}
submitLockers(finalArr);
}
onMount(async () => {
//
await checkIDs();
});
</script>

<div class="main" in:slide={{ delay: 250, duration: 600, easing: quartOut, axis: 'x' }}>
<div class="box">
<div class="box-cont">
<div class="box-header">Select locker Location</div>
<div class="box-header">Confirm Locker Selection</div>
<div class="small-text">Your locker is assigned randomly</div>
<div class="selection-div">

Expand Down
55 changes: 37 additions & 18 deletions src/routes/(app)/register/views/Selection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,78 @@
import {slide} from "svelte/transition";
import {quartOut} from "svelte/easing";
import {singleLocker, studentId1, studentId2, selectedLocation, pageView} from "../store.js";
import {fetchAvailableLockers} from "$lib/services/app/mainApi.js";
import Select from "$lib/components/app/Select.svelte";
let buttonMessage = 'Submit';
let data1 = ['1000', '2000', '7000'];
let data2 = ['1', '2', '3'];
let data3 = ['Top', 'Single', 'Bottom'];
let areas = {};
let data1 = [];
let data2 = [];
let data3 = ['Top', 'Single', 'Bottom'];
let value1;
let value1;
let value2;
let value3;
async function fetchData() {
areas = await fetchAvailableLockers();
// Update data1 based on fetched areas
data1 = Object.keys(areas);
// Check if value1 is selected and update data2 accordingly
if (value1 && areas[value1.value]) {
data2 = areas[value1.value];
}
}
function next() {
// console.log(value2)
//todo ge tform feilds
async function next() {
selectedLocation.set({
building: value1.label,
floor: value2.label,
position: value3.label,
})
console.log($selectedLocation)
level: value3.label,
});
console.log($selectedLocation);
pageView.set(2);
}
onMount(async () => {
await fetchData();
});
// Watch for changes in value1 and update data2 accordingly
$: {
if (value1 && areas[value1.value]) {
console.log("feuj")
data2 = areas[value1.value];
clear();
}
}
function clear(){
value2 = null;
value3 = null;
}
</script>

<div class="main" in:slide={{ delay: 250, duration: 600, easing: quartOut, axis: 'x' }}>
<div class="box">
<div class="box-cont">
<div class="box-header">Select locker Location</div>

<div class="selection-div">

<div class="input-group">
<div class="selection-label">Building</div>
<Select items={data1} placeholder="Select Building" bind:value={value1}/>
</div>

<div class="input-group">
<div class="selection-label">Floor</div>
<Select items={data2} placeholder="Select Floor" bind:value={value2}/>
Expand Down
6 changes: 3 additions & 3 deletions src/routes/(app)/register/views/View2.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {writable} from "svelte/store";
import {slide} from "svelte/transition";
import {quartOut} from "svelte/easing";
import {singleLocker, studentId1, studentId2} from "../store.js";
import {singleLocker, studentId1, studentId2, pageView} from "../store.js";
import {checkVerification} from "$lib/services/app/mainApi.js";
Expand All @@ -25,7 +25,7 @@
studentStatusStore.set({student_1: json.verified});
if($studentStatusStore.student_1) console.log("one verified");
if($studentStatusStore.student_1) pageView.set(4);
}else{
let response1 = await checkVerification($studentId1);
let response2 = await checkVerification($studentId2);
Expand All @@ -34,7 +34,7 @@
studentStatusStore.set({student_1: json1.verified, student_2: json2.verified});
if($studentStatusStore.student_1 && $studentStatusStore.student_2) console.log("both verified");
if($studentStatusStore.student_1 && $studentStatusStore.student_2) pageView.set(4);
}
Expand Down

0 comments on commit 1360251

Please sign in to comment.