-
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 #237 from ShivanshPlays/multistep-form2
Implement Individual Forms and Submission Logic for Guided Multistep Form in Vendor Dashboard
- Loading branch information
Showing
13 changed files
with
728 additions
and
6 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
alimento-nextjs/components/multistepForm/components/formControl.tsx
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,55 @@ | ||
import React from 'react'; | ||
|
||
// Define the type for the props | ||
interface FormControlProps { | ||
type: string; | ||
id: string; | ||
label: string; | ||
placeholder: string; | ||
value: string; | ||
onchange: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
valid: boolean; | ||
} | ||
|
||
const FormControl: React.FC<FormControlProps> = ({ | ||
type, | ||
id, | ||
label, | ||
placeholder, | ||
value, | ||
onchange, | ||
valid, | ||
}) => { | ||
return ( | ||
<div className="flex flex-col gap-1"> | ||
<div className="flex"> | ||
<div className="mr-auto"> | ||
<label className="text-primary-marineBlue font-medium" htmlFor={id}> | ||
{label} | ||
</label> | ||
</div> | ||
{valid ? null : ( | ||
<div> | ||
<label className="text-red-500 font-medium" htmlFor={id}> | ||
This field is required | ||
</label> | ||
</div> | ||
)} | ||
</div> | ||
<input | ||
id={id} | ||
className={ | ||
valid | ||
? 'w-full p-2 rounded-lg text-lg outline-none focus:border-primary-purplishBlue duration-700 border border-secondary-lightGray' | ||
: 'w-full p-2 rounded-lg text-lg outline-none focus:border-primary-strawberryRed duration-700 border border-primary-strawberryRed' | ||
} | ||
type={type} | ||
placeholder={placeholder} | ||
value={value} | ||
onChange={onchange} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormControl; |
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ export const data = [ | |
}, | ||
{ | ||
id: 3, | ||
step: 'step 4', | ||
step: 'step 3', | ||
title: 'select tags', | ||
}, | ||
]; | ||
|
66 changes: 66 additions & 0 deletions
66
alimento-nextjs/components/multistepForm/components/tagSelector.tsx
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,66 @@ | ||
import { | ||
Select, | ||
SelectTrigger, | ||
SelectValue, | ||
SelectContent, | ||
SelectItem, | ||
} from "@/components/ui/select"; | ||
import { useGlobalDish } from "@/context/dishFormContext"; | ||
import { Tag } from "@prisma/client"; | ||
import { useState } from "react"; | ||
|
||
const TagSelector = () => { | ||
const tags = Object.values(Tag) | ||
const {dishTags,setDishTags} = useGlobalDish() | ||
|
||
const handleTagSelect = (tag:Tag) => { | ||
if (!dishTags.includes(tag)) { | ||
setDishTags([...dishTags, tag]); | ||
} | ||
}; | ||
|
||
const handleRemoveTag = (tag:Tag) => { | ||
setDishTags(dishTags.filter((t) => t !== tag)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="mb-2"> | ||
<Select onValueChange={handleTagSelect}> | ||
<SelectTrigger className="w-64"> | ||
<SelectValue placeholder="Select tags" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{tags.map((tag) => ( | ||
<SelectItem key={tag} value={tag}> | ||
{tag} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
|
||
{/* Selected Tags */} | ||
<div className="flex flex-wrap gap-2 mt-2"> | ||
{dishTags.map((tag) => ( | ||
<span | ||
key={tag} | ||
className="bg-blue-200 text-blue-800 px-3 py-1 rounded-full flex items-center space-x-2" | ||
> | ||
<span>{tag}</span> | ||
<button | ||
type="button" | ||
onClick={() => handleRemoveTag(tag)} | ||
className="text-sm text-blue-600" | ||
> | ||
× | ||
</button> | ||
</span> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TagSelector; | ||
|
81 changes: 81 additions & 0 deletions
81
alimento-nextjs/components/multistepForm/pages/formPage1.tsx
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,81 @@ | ||
import React from 'react'; | ||
import { useGlobalDish } from '@/context/dishFormContext'; | ||
import FormControl from '../components/formControl'; | ||
|
||
const FormPage1 = () => { | ||
const { | ||
dishName, | ||
setDishName, | ||
dishPrice, | ||
setDishPrice, | ||
dishDescription, | ||
setDishDescription, | ||
|
||
validDishName, | ||
setValidDishName, | ||
validDishPrice, | ||
setValidDishPrice, | ||
validDishDescription, | ||
setValidDishDescription, | ||
} = useGlobalDish(); | ||
|
||
const setDishNameLogic = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setDishName(e.target.value); | ||
setValidDishName(e.target.value.length >= 1); | ||
}; | ||
|
||
const setDishDescriptionLogic = ( | ||
e: React.ChangeEvent<HTMLInputElement> | ||
) => { | ||
setDishDescription(e.target.value); | ||
setValidDishDescription(e.target.value.length >= 1); | ||
}; | ||
|
||
const setDishPriceLogic = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setDishPrice(Number(e.target.value)); | ||
setValidDishPrice(e.target.value.length >= 1); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col gap-8"> | ||
<h1 className="text-primary-marineBlue font-bold text-[1.6rem] md:text-4xl leading-9"> | ||
Dish Info | ||
</h1> | ||
<h3 className="text-gray-400 mt-2"> | ||
Please provide your Dish name, description and price | ||
</h3> | ||
|
||
<div className="flex flex-col gap-5"> | ||
<FormControl | ||
label={'Dish Title'} | ||
type={'text'} | ||
id={'dishName'} | ||
placeholder={'pizza'} | ||
onchange={setDishNameLogic} | ||
value={dishName} | ||
valid={validDishName} | ||
/> | ||
<FormControl | ||
label={'Dish Description'} | ||
type={'text'} | ||
id={'dishDescription'} | ||
placeholder={'large - 8 slices, margherita'} | ||
onchange={setDishDescriptionLogic} | ||
value={dishDescription} | ||
valid={validDishDescription} | ||
/> | ||
<FormControl | ||
label={'Dish Price'} | ||
type={'number'} | ||
id={'dishPrice'} | ||
placeholder={'e.g. example@upi'} | ||
onchange={setDishPriceLogic} | ||
value={dishPrice.toString()} | ||
valid={validDishPrice} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormPage1; |
47 changes: 47 additions & 0 deletions
47
alimento-nextjs/components/multistepForm/pages/formPage2.tsx
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,47 @@ | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu'; | ||
import { useGlobalDish } from '@/context/dishFormContext'; | ||
import { Category, Prisma } from '@prisma/client'; | ||
import { ChevronDown } from 'lucide-react'; | ||
|
||
const categories =Object.values(Category) | ||
|
||
const FormPage2 = () => { | ||
const { dishCategory,setDishCategory } = useGlobalDish(); | ||
|
||
return ( | ||
<div className="h-3/4 flex flex-col items-start gap-8 justify-start"> | ||
<h1 className="text-primary-marineBlue font-bold text-[1.6rem] md:text-4xl leading-9"> | ||
Select Category | ||
</h1> | ||
<h3 className="text-gray-400 mt-2"> | ||
Please select the most appropriate category for your dish | ||
</h3> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="bg-black h-10 text-gray-200 w-full rounded-full flex items-center justify-center"> | ||
{dishCategory || 'Category'} <ChevronDown /> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuLabel> | ||
Select the Category for your dish | ||
</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
{categories.map((category)=>( | ||
<DropdownMenuItem key={category} onClick={() => setDishCategory(category)}> | ||
{category} | ||
</DropdownMenuItem> | ||
))} | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormPage2; | ||
|
19 changes: 19 additions & 0 deletions
19
alimento-nextjs/components/multistepForm/pages/formPage3.tsx
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,19 @@ | ||
import TagSelector from '../components/tagSelector'; | ||
|
||
const FormPage3 = () => { | ||
|
||
return ( | ||
<div className="h-3/4 flex flex-col items-start gap-8 justify-start"> | ||
<h1 className="text-primary-marineBlue font-bold text-[1.6rem] md:text-4xl leading-9"> | ||
Select Tags | ||
</h1> | ||
<h3 className="text-gray-400 mt-2"> | ||
Please select the most appropriate tags for your dish | ||
</h3> | ||
<TagSelector/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormPage3; | ||
|
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
Oops, something went wrong.