Skip to content

Commit

Permalink
user and shopowner completed
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush7833 committed Feb 3, 2024
1 parent 40127ea commit 0baf5ce
Show file tree
Hide file tree
Showing 31 changed files with 821 additions and 160 deletions.
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.18",
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.4",
Expand All @@ -29,6 +31,7 @@
"eslint": "8.45.0",
"eslint-config-next": "13.4.10",
"firebase": "^10.7.2",
"gsap": "^3.12.5",
"js-cookie": "^3.0.5",
"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
Expand Down
Binary file added public/images/error500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/loader2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/not-found.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/images/not-found.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions src/app/add-product/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
"use client"
import Image from 'next/image';
import React, { useState, useRef } from 'react'
import AddIcon from '@mui/icons-material/Add';
import React, { useState } from 'react'
import { useRouter } from 'next/navigation';
import { useSession } from 'next-auth/react';
import DeleteIcon from '@mui/icons-material/Delete';
import { baseUrl } from '@/baseUrl';
import { userAuthStore } from '@/utils/userStore';
import ImgContainer from '@/components/common/ImgContainer';
import { toast } from 'react-toastify';
import axios from 'axios';
Expand Down Expand Up @@ -78,7 +73,7 @@ const AddPage = ({params}:Props) => {
<div className=" w-full h-1/2 md:h-1/2 md:w-1/2 flex items-center justify-center">
<ImgContainer type='singleProduct' alt='add image' edit={true} func={handleImageChange} />
</div>
<FormContainer onSave={handleSave} data={addProductFormData} title="Add Product" />
<FormContainer onSave={handleSave} data={addProductFormData} title="Add Product" additional={true} />
</div>
)
}
Expand Down
50 changes: 50 additions & 0 deletions src/app/api/forgetpasswrod/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { NextRequest, NextResponse } from "next/server";
import { getUserDetails } from "../utils/action";
import { prisma } from "@/utils/connect";
import bcrypt from "bcryptjs";

export const PUT=async(req:NextRequest)=>{
try {
// console.log(await req.json())
const {current_password,password,confirm_password}:{current_password:string,password:string,confirm_password:string}=await req.json();
const user=await getUserDetails(req);
if(user===null){
return NextResponse.json({
error:true,
message:"Login first to change password",
status:403
},{status:403})
}
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(password, salt);
const userPassword=user.password;
const isCorrect= await bcrypt.compare(current_password,userPassword!);
if(!isCorrect){
return NextResponse.json({
error:true,
message:"Current password provided is wrong.",
status:403
},{status:403})
}
const updatedUser=await prisma.user.update({
where:{
id:user.id
},
data:{
password:hashedPassword
}
})
return NextResponse.json({
error:true,
message:"User password updated successfully",
status:200
},{status:200})
} catch (error) {
console.log(error)
return NextResponse.json({
error:true,
message:"Something went wrong",
status:404
})
}
}
2 changes: 1 addition & 1 deletion src/app/api/orders/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const POST = async (req: NextRequest) => {
}
}

export const GET = async (req: NextRequest) => { //get all orders of shopOwner all shops
export const GET = async (req: NextRequest) => { //get all orders of shopOwner all shops or user
try {
const user = await getUserDetails(req);
let orders;
Expand Down
50 changes: 50 additions & 0 deletions src/app/api/payment/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { NextRequest, NextResponse } from "next/server";
import { getUserDetails } from "../utils/action";
import { prisma } from "@/utils/connect";
import bcrypt from "bcryptjs";

export const PUT=async(req:NextRequest)=>{
try {
// console.log(await req.json())
const {current_password,password,confirm_password}:{current_password:string,password:string,confirm_password:string}=await req.json();
const user=await getUserDetails(req);
if(user===null){
return NextResponse.json({
error:true,
message:"Login first to change password",
status:403
},{status:403})
}
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(password, salt);
const userPassword=user.password;
const isCorrect= await bcrypt.compare(current_password,userPassword!);
if(!isCorrect){
return NextResponse.json({
error:true,
message:"Current password provided is wrong.",
status:403
},{status:403})
}
const updatedUser=await prisma.user.update({
where:{
id:user.id
},
data:{
password:hashedPassword
}
})
return NextResponse.json({
error:true,
message:"User password updated successfully",
status:200
},{status:200})
} catch (error) {
console.log(error)
return NextResponse.json({
error:true,
message:"Something went wrong",
status:404
})
}
}
8 changes: 0 additions & 8 deletions src/app/api/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import { getUserDetails } from "../utils/action";
import { prisma } from "@/utils/connect";
import { cookies } from 'next/headers'

export const verifyEmail = async () => {

}

export const verifyPhone = async () => {

}

export const PUT = async (req: NextRequest) => {
try {
// let {name,email,phone,image}:updateForm=await req.json();
Expand Down
99 changes: 99 additions & 0 deletions src/app/edit-product/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"use client"
import { productType } from '@/app/api/product/type'
import { baseUrl } from '@/baseUrl'
import ConfirmDialog from '@/components/common/ConfirmDialog'
import FormContainer from '@/components/common/FormContainer'
import ImgContainer from '@/components/common/ImgContainer'
import Loader from '@/components/common/Loader'
import { productOptionType } from '@/types/types'
import { editProductFormData } from '@/utils/formData'
import axios from 'axios'
import { useRouter } from 'next/navigation'
import React, { useEffect, useState } from 'react'
import { toast } from 'react-toastify'
type Props={
params:{id:string}
}
const Page = ({params}:Props) => {
const [data,setData]=useState<any>()
const [selectedImage, setSelectedImage] = useState<File | null>(null);
const [isConfirmOpen, setConfirmOpen] = useState(false);
const [productData, setProductData] = useState<productType>()
const router = useRouter()
const [options, setOptions] = useState<productOptionType[]>([])
useEffect(() => {
const getData = async (id:string) => {
try {
const response = await axios.get(`${baseUrl}/product/${id}`)
setData(response.data);
} catch (error: any) {
setData(error.response)
}
}
getData(params.id)
}, [params.id])

const handleUploadImage = async () => {
try {
const formData = new FormData();
formData.append('file', selectedImage!);
formData.append('type', "single");
const imageResponse = await axios.post(`${baseUrl}/upload-image`, formData)
return imageResponse.data.imgUrls;
} catch (error) {
toast.error("Image upload failed")
return null;
}
}
const handleSubmit = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
try {
let imgUrl;
if (selectedImage) {
imgUrl = await handleUploadImage()
}
const response = await axios.put(`${baseUrl}/product/${params.id}`, {title:productData?.title,desc:productData?.desc,type:productData?.type,img:imgUrl,options, price:productData?.price})
toast.success(response.data.message);
router.push(`/product/${response.data.updatedProduct.id}`)
} catch (error: any) {
console.log(error)
toast.error(error.response.data.message)
}
}
const handleImageChange = (selectedImage: File | null) => {
setSelectedImage(selectedImage);
};
const handleSave = async (formDetails: productType, optionDetails: productOptionType[]) => {
try {
setProductData(formDetails)
setOptions(optionDetails)
setConfirmOpen(true)
} catch (error) {
toast.error("Something went wrong")
}
}
if(data && data.error){
return <div>Something went wrong</div>
}
if(!data){
return <Loader message='Edit food details easliy on munch' />
}
return (
<div>
<div className='main flex flex-col md:flex-row gap-14 md:gap-4 items-center justify-center hideScrollBar w-full'>
<ConfirmDialog
isOpen={isConfirmOpen}
onClose={() => setConfirmOpen(false)}
onConfirm={handleSubmit}
title="Confirm Action"
message="Are you sure you want to perform this action?"
/>
<div className=" w-full h-1/2 md:h-1/2 md:w-1/2 flex items-center justify-center">
<ImgContainer type='singleProduct' alt='add image' edit={true} imgUrl={data.product.img} func={handleImageChange} />
</div>
<FormContainer onSave={handleSave} data={editProductFormData} originalData={data.product} originalAdditionalOptions={data.product.options} additional={true} title="Edit shop" />
</div>
</div>
)
}

export default Page
Loading

0 comments on commit 0baf5ce

Please sign in to comment.