Skip to content

Commit

Permalink
Adding got a job button changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsiesmurphy committed May 25, 2023
1 parent 0ae745f commit 6c34841
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
34 changes: 28 additions & 6 deletions components/dashboard/GotAJobButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { Fragment, useState } from "react";
import { X } from "react-feather";
import { createJobApplicationPeriod } from "@/handlers/JobApplicationPeriodHandler";
import { updateUserApplicationPeriod } from "@/handlers/AuthHandler";
import { updateJobApplicationPeriodEndDate } from "@/handlers/JobApplicationPeriodHandler";
import trophy from "../../assets/trophy.svg";
import Image from "next/image";
import confetti from "canvas-confetti";
import Router from "next/router";

const GotAJobButton = ({ supabase, userProfile, setUserProfile }: any) => {
let [isOpen, setIsOpen] = useState(false);
const [confirmInput, setConfirmInput] = useState("");

const handleConfetti = () => {
confetti({
Expand All @@ -17,17 +20,28 @@ const GotAJobButton = ({ supabase, userProfile, setUserProfile }: any) => {
});
};

const handleGotAJob = () => {
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));

const handleGotAJob = async () => {
try {
updateJobApplicationPeriodEndDate(
supabase,
userProfile.current_application_period_id
);
createJobApplicationPeriod(supabase, userProfile).then((periodId) => {
updateUserApplicationPeriod(supabase, userProfile.id, periodId);
updateUserApplicationPeriod(supabase, userProfile.id, periodId).then(
(updatedUserProfile) => {
setUserProfile(updatedUserProfile);
}
);
});
handleConfetti();
setIsOpen(false);
await delay(3000);
Router.reload();
} catch (error) {
alert("Error submitting application");
console.log(error);
} finally {
setIsOpen(false);
}
};

Expand Down Expand Up @@ -93,11 +107,18 @@ const GotAJobButton = ({ supabase, userProfile, setUserProfile }: any) => {
</h1>
<p className="text-sm text-stone-600">
If you've got a job, you won't be needing this list
anymore! Click “confirm” below to clear your list of
anymore! Type 'CONFIRM' below to clear your list of
applications, and it will be ready for you if you decide
to use it again in the future!
</p>
</div>
<input
className="input w-full"
onChange={(e) => setConfirmInput(e.target.value)}
value={confirmInput}
name="confirmInput"
placeholder="CONFIRM"
/>
</Dialog.Title>
<div className="flex flex-wrap flex-1 gap-4">
<button
Expand All @@ -108,7 +129,8 @@ const GotAJobButton = ({ supabase, userProfile, setUserProfile }: any) => {
</button>
<button
className="btn-primary flex-1 max-w-none"
onClick={handleGotAJob}
onClick={() => handleGotAJob()}
disabled={confirmInput !== "CONFIRM"}
>
Confirm
</button>
Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { createJobApplicationPeriod } from "@/handlers/JobApplicationPeriodHandler";
import { selectJobApplicationPeriod } from "@/handlers/JobApplicationPeriodHandler";
import { getApplicationsByPeriod } from "@/handlers/ApplicationHandler";
import { getAllStages } from "@/handlers/StageHandler";
import TableLine from "./TableLine";
Expand Down Expand Up @@ -35,7 +35,7 @@ const Table = ({ userProfile, supabase }: any) => {
async function getJobApplicationPeriod(userProfile: any) {
try {
if (userProfile.current_application_period_id) {
createJobApplicationPeriod(supabase, userProfile).then(
selectJobApplicationPeriod(supabase, userProfile).then(
(jobApplicationPeriod) => {
setJobApplicationPeriod(jobApplicationPeriod[0]);
getApplications(jobApplicationPeriod[0]);
Expand Down
2 changes: 1 addition & 1 deletion components/index/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Navigation = ({ children }: any) => {
className="bg-white border-b border-stone-100 flex justify-between py-4 px-4 md:px-20 transition-all"
>
<div className="flex gap-4 items-center">
<a href="">
<a href="/">
<Logo />
</a>
<a href="#faq" className="hidden md:block text-stone-700 font-semibold">
Expand Down
11 changes: 11 additions & 0 deletions handlers/JobApplicationPeriodHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ export const selectJobApplicationPeriod = async (supabase:any, userProfile:any)
return data;
};

export const updateJobApplicationPeriodEndDate = async (supabase:any, jobApplicationId:string) => {
const { data, error } = await supabase
.from("job_application_period")
.update({ end_date: new Date().toISOString().toLocaleString() })
.eq('id', jobApplicationId)
if (error) {
throw error;
}
return data;
};

export const createJobApplicationPeriod = async (supabase:any, userProfile:any) => {
const { data, error } = await supabase
.from("job_application_period")
Expand Down

0 comments on commit 6c34841

Please sign in to comment.