-
Notifications
You must be signed in to change notification settings - Fork 70
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 #232 from ShivanshPlays/multistep-form
addeed the global context and seperated the vendor and customer side of the website and added conditional logic on vendor dashboard page
- Loading branch information
Showing
5 changed files
with
189 additions
and
2 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,18 @@ | ||
import Navbar from "@/components/common/navbar"; | ||
import Footer from "@/components/common/footer"; | ||
|
||
export default function CustomerLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Navbar/> | ||
{children} | ||
<Footer/> | ||
</body> | ||
</html> | ||
); | ||
} |
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,38 @@ | ||
import prismadb from '@/lib/prismadb'; | ||
import { Dish } from '@prisma/client'; | ||
|
||
interface VendorPageProps { | ||
params: { | ||
vendorId: string; | ||
}; | ||
} | ||
|
||
const VendorPage: React.FC<VendorPageProps> = async ({ params }) => { | ||
let Dishes: Dish[] | null = []; | ||
|
||
const { vendorId } = await params; | ||
try { | ||
Dishes = await prismadb.dish.findMany({ | ||
where: { | ||
vendorId: vendorId, | ||
}, | ||
}); | ||
} catch (err) { | ||
console.error( | ||
'Error fetching Dishes', | ||
err instanceof Error ? err.message : err | ||
); | ||
} | ||
|
||
if (Dishes.length){ | ||
return <div>this will be the dishes page</div> | ||
} | ||
|
||
else{ | ||
// return <SetUpDishes VendorId={vendorId}/> | ||
// here the guided form component will be added s | ||
} | ||
|
||
} | ||
|
||
export default VendorPage; |
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,14 @@ | ||
|
||
export default function VendorLayout({ | ||
children, | ||
}: Readonly<{ | ||
children: React.ReactNode; | ||
}>) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
{children} | ||
</body> | ||
</html> | ||
); | ||
} |
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,119 @@ | ||
"use client"; | ||
import { Category, Tag } from "@prisma/client"; | ||
import { | ||
createContext, | ||
ReactNode, | ||
useCallback, | ||
useContext, | ||
useState, | ||
} from "react"; | ||
import toast from "react-hot-toast"; | ||
|
||
interface GlobalContextType { | ||
currentStep: number; | ||
setCurrentStep: (step: number) => void; | ||
completed: boolean; | ||
setCompleted: (completed: boolean) => void; | ||
|
||
dishName: string; | ||
setDishName: (name: string) => void; | ||
dishPrice: number; | ||
setDishPrice: (price: number) => void; | ||
dishDescription: string; | ||
setDishDescription: (description: string) => void; | ||
dishCategory: Category; | ||
setDishCategory: (category: Category) => void; | ||
dishTags: Tag[]; | ||
setDishTags: (tags: Tag[]) => void; | ||
|
||
validDishName: boolean; | ||
setValidDishName: (valid: boolean) => void; | ||
validDishPrice: boolean; | ||
setValidDishPrice: (valid: boolean) => void; | ||
validDishDescription: boolean; | ||
setValidDishDescription: (valid: boolean) => void; | ||
validDishCategory: boolean; | ||
setValidDishCategory: (valid: boolean) => void; | ||
validDishTags: boolean; | ||
setValidDishTags: (valid: boolean) => void; | ||
|
||
checkedBox: boolean; | ||
setCheckedBox: (checkedBox: boolean) => void; | ||
|
||
formCompleted: boolean; | ||
setFormCompleted: (completed: boolean) => void; | ||
} | ||
|
||
export const GlobalDishContext = createContext<GlobalContextType | undefined>( | ||
undefined | ||
); | ||
|
||
export const useGlobalDish = () => { | ||
const context = useContext(GlobalDishContext); | ||
if (!context) { | ||
throw new Error("useGlobalDish must be used within a GlobalDishProvider"); | ||
} | ||
return context; | ||
}; | ||
|
||
export const GlobalDishProvider = ({ children }: { children: ReactNode }) => { | ||
const [currentStep, setCurrentStep] = useState(1); | ||
const [completed, setCompleted] = useState(false); | ||
|
||
const [dishName, setDishName] = useState(""); | ||
const [dishPrice, setDishPrice] = useState(0); | ||
const [dishDescription, setDishDescription] = useState(""); | ||
const [dishCategory, setDishCategory] = useState<Category>( | ||
Category.APPETIZER | ||
); | ||
const [dishTags, setDishTags] = useState<Tag[]>([]); | ||
|
||
const [validDishName, setValidDishName] = useState(false); | ||
const [validDishPrice, setValidDishPrice] = useState(false); | ||
const [validDishDescription, setValidDishDescription] = useState(false); | ||
const [validDishCategory, setValidDishCategory] = useState(false); | ||
const [validDishTags, setValidDishTags] = useState(false); | ||
|
||
const [checkedBox, setCheckedBox] = useState(false); | ||
const [formCompleted, setFormCompleted] = useState(false); | ||
|
||
return ( | ||
<GlobalDishContext.Provider | ||
value={{ | ||
currentStep, | ||
setCurrentStep, | ||
completed, | ||
setCompleted, | ||
|
||
dishName, | ||
setDishName, | ||
dishPrice, | ||
setDishPrice, | ||
dishDescription, | ||
setDishDescription, | ||
dishCategory, | ||
setDishCategory, | ||
dishTags, | ||
setDishTags, | ||
|
||
validDishName, | ||
setValidDishName, | ||
validDishPrice, | ||
setValidDishPrice, | ||
validDishDescription, | ||
setValidDishDescription, | ||
validDishCategory, | ||
setValidDishCategory, | ||
validDishTags, | ||
setValidDishTags, | ||
|
||
checkedBox, | ||
setCheckedBox, | ||
formCompleted, | ||
setFormCompleted, | ||
}} | ||
> | ||
{children} | ||
</GlobalDishContext.Provider> | ||
); | ||
}; |