Skip to content

Commit

Permalink
Merge pull request #232 from ShivanshPlays/multistep-form
Browse files Browse the repository at this point in the history
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
Vimall03 authored Nov 7, 2024
2 parents e5a32ce + 70bd86a commit d136a20
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 2 deletions.
18 changes: 18 additions & 0 deletions alimento-nextjs/app/(PublicRoutes)/layout.tsx
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>
);
}
2 changes: 0 additions & 2 deletions alimento-nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export default function RootLayout({
<html lang="en">
<body>
<Providers>
<Navbar/>
{children}
<Footer/>
</Providers>
</body>
</html>
Expand Down
38 changes: 38 additions & 0 deletions alimento-nextjs/app/vendor/[vendorId]/page.tsx
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;
14 changes: 14 additions & 0 deletions alimento-nextjs/app/vendor/layout.tsx
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>
);
}
119 changes: 119 additions & 0 deletions alimento-nextjs/context/dishFormContext.tsx
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>
);
};

0 comments on commit d136a20

Please sign in to comment.