-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from podcodar/vitorschelb/form-validation
Validates data from form steps according to zod schemas.
- Loading branch information
Showing
10 changed files
with
150 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client"; | ||
import { PropsWithChildren } from "react"; | ||
import { OnboardingProvider, Step } from "@/contexts/OnboardingFormProvider"; | ||
import OnboardingRegistration from "@/components/forms/OnboardingRegistration"; | ||
import OnboardingContact from "@/components/forms/OnboardingContact"; | ||
import OnboardingProfessional from "@/components/forms/OnboardingProfessional"; | ||
import OnboardingAbout from "@/components/forms/OnboardingAbout"; | ||
import { useSearchParams } from "next/navigation"; | ||
|
||
const steps: Step[] = [ | ||
{ content: OnboardingRegistration }, | ||
{ content: OnboardingContact }, | ||
{ content: OnboardingProfessional }, | ||
{ content: OnboardingAbout }, | ||
]; | ||
|
||
export default async function OnboardingLayout({ | ||
children, | ||
}: PropsWithChildren) { | ||
const searchParams = useSearchParams(); | ||
const initialStep = searchParams.get("step") ?? "0"; | ||
|
||
return ( | ||
<OnboardingProvider initialStep={Number(initialStep)} steps={steps}> | ||
{children} | ||
</OnboardingProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use client"; | ||
import { FC, useState, createContext, ReactNode, useContext } from "react"; | ||
import { raise } from "@/shared/exceptions"; | ||
|
||
type OnboardingContextProps = { | ||
steps: Step[]; | ||
children: ReactNode; | ||
initialStep?: number; | ||
}; | ||
|
||
export type Step = { | ||
content: FC; | ||
}; | ||
|
||
type OnboardingContextValues = { | ||
step: number; | ||
steps: Step[]; | ||
canMovePrevious: boolean; | ||
canMoveNext: boolean; | ||
content: FC; | ||
moveNextStep: () => void; | ||
movePrevStep: () => void; | ||
}; | ||
|
||
export const OnboardingProvider: FC<OnboardingContextProps> = ({ | ||
steps, | ||
children, | ||
initialStep = 0, | ||
}) => { | ||
const [step, setStep] = useState(initialStep); | ||
const canMovePrevious = step !== 0; | ||
const canMoveNext = step !== steps.length - 1; | ||
const { content } = steps[step]; | ||
|
||
//TODO: Create ActionFunction to abrigate | ||
// const actions = createActions(...states) | ||
function moveNextStep() { | ||
if (!canMoveNext) return; | ||
setStep((step) => step + 1); | ||
} | ||
|
||
function movePrevStep() { | ||
if (!canMovePrevious) return; | ||
setStep((step) => step - 1); | ||
} | ||
|
||
// const values = createValues(...states) | ||
const values: OnboardingContextValues = { | ||
step, | ||
steps, | ||
canMovePrevious, | ||
canMoveNext, | ||
content, | ||
moveNextStep, | ||
movePrevStep, | ||
}; | ||
|
||
return ( | ||
<OnboardingContext.Provider value={values}> | ||
{children} | ||
</OnboardingContext.Provider> | ||
); | ||
}; | ||
|
||
export const useOnboardingContext = (): OnboardingContextValues => { | ||
const context = useContext(OnboardingContext); | ||
if (!context) return raise("No OnboardingContext found"); | ||
return context; | ||
}; | ||
|
||
const OnboardingContext = createContext<OnboardingContextValues | null>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const raise = (error: string): never => { | ||
throw new Error(error); | ||
}; |
6cd9c99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
app – ./
app-git-main-podcodar.vercel.app
app-podcodar.vercel.app
app-zeta-two.vercel.app
app.podcodar.com