Skip to content

Commit b78a86a

Browse files
committed
extracted progress value and put it into stepper-store
1 parent 0f1c59a commit b78a86a

File tree

10 files changed

+31
-20
lines changed

10 files changed

+31
-20
lines changed

app/code-area/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Button } from "@/components/ui/button";
99
import { useRouter } from "next/navigation";
1010
import { cn } from "@/lib/utils";
1111
import useCodeAreaStore from "@/data-store/code-area-store";
12-
import useStepperStore from "@/data-store/stepper-store";
12+
import { useStepperStore } from "@/data-store/stepper-store";
1313
import validateUser from "@/lib/validate-user";
1414

1515
type MosaicKey = "EDITOR" | "PREVIEW";

components/core/editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import useCodeAreaStore from "@/data-store/code-area-store";
99
import { Button } from "../ui/button";
1010
import StaticPrompt from "./target-image";
1111
import LandingPageChallengeCode from "../landing/test-challenges/challenge-code";
12-
import useStepperStore from "@/data-store/stepper-store";
12+
import { useStepperStore } from "@/data-store/stepper-store";
1313

1414
const Editor = () => {
1515
const { code, setCode } = useSessionStore();

components/ui/useCode/Email-FormField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
FormMessage,
77
} from "@/components/ui/form";
88
import { Input } from "@/components/ui/input";
9-
import useStepperStore from "@/data-store/stepper-store";
9+
import { useStepperStore } from "@/data-store/stepper-store";
1010

1111
export function EmailFormField(form: any) {
1212
const { email } = useStepperStore();

components/ui/useCode/StepOne.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import * as z from "zod";
33
import { useForm } from "react-hook-form";
44
import { Button } from "@/components/ui/button";
55
import { Form } from "@/components/ui/form";
6-
import useStepperStore from "@/data-store/stepper-store";
6+
import {
7+
useStepperStore,
8+
progressIncrements,
9+
} from "@/data-store/stepper-store";
710
import { EmailFormField } from "./Email-FormField";
811
import { TOSFormField } from "./TOS-FormField";
912
import { FormSubmitting } from "./Submitting";
@@ -12,8 +15,6 @@ export function StepOne() {
1215
const { progress, setProgress, step, setStep, email, setEmail, setCheck } =
1316
useStepperStore();
1417

15-
const PROGRESS_INCREMENT: number = 33;
16-
1718
const formStepOneSchema = z.object({
1819
email: z
1920
.string()
@@ -42,7 +43,7 @@ export function StepOne() {
4243
setCheck(values.accept);
4344

4445
if (step === 1) {
45-
setProgress(progress + PROGRESS_INCREMENT);
46+
setProgress(progress + progressIncrements);
4647
setStep(step + 1);
4748
}
4849
}

components/ui/useCode/StepTwo.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import * as z from "zod";
33
import { useForm } from "react-hook-form";
44
import { Button } from "@/components/ui/button";
55
import { Form } from "@/components/ui/form";
6-
import useStepperStore from "@/data-store/stepper-store";
6+
import {
7+
progressIncrements,
8+
useStepperStore,
9+
} from "@/data-store/stepper-store";
710
import { FormSubmitting } from "./Submitting";
811
import useSessionStore from "@/data-store/session-store";
912
import LandingPageCode from "@/components/landing/test-challenges/placeholder-code";
@@ -20,8 +23,6 @@ const formStepTwoSchema = z.object({
2023
});
2124

2225
export function StepTwo() {
23-
const PROGRESS_INCREMENT: number = 33;
24-
2526
const { progress, setProgress, step, setStep, setChallenge } =
2627
useStepperStore();
2728
const { setCode } = useSessionStore();
@@ -39,14 +40,14 @@ export function StepTwo() {
3940
console.log(selection);
4041
setCode(LandingPageCode());
4142
setChallenge(selection);
42-
setProgress(progress + PROGRESS_INCREMENT);
43+
setProgress(progress + progressIncrements);
4344

4445
router.push("/code-area");
4546
}
4647
}
4748

4849
async function onBack() {
49-
setProgress(progress - PROGRESS_INCREMENT);
50+
setProgress(progress - progressIncrements);
5051
setStep(step - 1);
5152
}
5253

components/ui/useCode/Stepper-Form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import useStepperStore from "@/data-store/stepper-store";
3+
import { useStepperStore } from "@/data-store/stepper-store";
44

55
import { StepOne } from "./StepOne";
66
import { StepTwo } from "./StepTwo";

components/ui/useCode/StepperCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "@/components/ui/card";
1010

1111
import { Progress } from "@/components/ui/progress";
12-
import useStepperStore from "@/data-store/stepper-store";
12+
import { useStepperStore } from "@/data-store/stepper-store";
1313
import { StepperForm } from "./Stepper-Form";
1414

1515
export function StepperCard() {

components/ui/useCode/TOS-FormField.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import {
77
FormMessage,
88
} from "@/components/ui/form";
99
import { Input } from "@/components/ui/input";
10-
import useStepperStore from "@/data-store/stepper-store";
10+
import {
11+
progressIncrements,
12+
useStepperStore,
13+
} from "@/data-store/stepper-store";
1114
import Link from "next/link";
1215

1316
let checked: boolean = false;
1417

1518
export function TOSFormField(form: any) {
1619
const { check, setCheck, progress, setProgress } = useStepperStore();
17-
const PROGRESS_INCREMENT: number = 33;
1820

1921
return (
2022
<FormField
@@ -29,12 +31,13 @@ export function TOSFormField(form: any) {
2931
checked={field.value}
3032
onChange={field.onChange}
3133
onClick={() => {
34+
console.log(progressIncrements);
3235
checked = !checked;
3336
setCheck(checked);
3437
setProgress(
3538
checked
36-
? progress + PROGRESS_INCREMENT
37-
: progress - PROGRESS_INCREMENT
39+
? progress + progressIncrements
40+
: progress - progressIncrements
3841
);
3942
}}
4043
className='peer mr-[10px] mt-[5px] h-4 w-[20px] cursor-pointer'

data-store/stepper-store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ const useStepperStore = create<StepperStore>((set) => ({
2626
setChallenge: (newChallenge) => set({ challenge: newChallenge }),
2727
}));
2828

29-
export default useStepperStore;
29+
const progessSteps: number = 3;
30+
const maxProgress: number = 100 - (100 % progessSteps);
31+
const progressIncrements: number = maxProgress / progessSteps;
32+
33+
export { useStepperStore, progessSteps, maxProgress, progressIncrements };

lib/validate-user.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* validationType is a variable created to trigger which conditional is returned to validate authorization to a section of the website.
22
Currently, it doesn't do anything, however it allows for more scalability if there are multiple different validations neccecary to authorize a user. */
33

4+
import { maxProgress } from "@/data-store/stepper-store";
5+
46
export default function validateUser(
57
validationType: string,
68
email?: string,
@@ -14,7 +16,7 @@ export default function validateUser(
1416
return (
1517
email === "" ||
1618
check === false ||
17-
progress !== (99 || 100) ||
19+
progress !== maxProgress ||
1820
challenge === ""
1921
);
2022
} else {

0 commit comments

Comments
 (0)