Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
- prettier & mobile-ux changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mertthesamael committed Sep 13, 2023
1 parent 4e10af0 commit ec4e7d0
Show file tree
Hide file tree
Showing 111 changed files with 2,368 additions and 1,906 deletions.
12 changes: 6 additions & 6 deletions actions/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const getURL = () => {
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
'http://localhost:3000/';
"http://localhost:3000/";

// Make sure to include https:// when not localhost.
url = url.includes('http') ? url : `https://${url}`;
url = url.includes("http") ? url : `https://${url}`;
// Make sure to including trailing /.
url = url.charAt(url.length - 1) === '/' ? url : `${url}/`;
url = url.charAt(url.length - 1) === "/" ? url : `${url}/`;
return url;
};

export const loginHandler = async (formData: FormData) => {
const email = String(formData.get("email"));
const password = String(formData.get("password"));
const supabase = createRouteHandlerClient({ cookies });
let user : TUser = null;
let user: TUser = null;
try {
const { data, error } = await supabase.auth.signInWithPassword({
email,
Expand Down Expand Up @@ -68,7 +68,7 @@ export const signupHandler = async (formData: FormData) => {
data: {
displayName: String(name),
email: String(email),
totalPrice:0
totalPrice: 0,
},
});
}
Expand All @@ -77,7 +77,7 @@ export const signupHandler = async (formData: FormData) => {
error: error,
};
} catch (err) {
console.log(err, '2313213123')
console.log(err, "2313213123");
} finally {
prisma.$disconnect();
}
Expand Down
1 change: 0 additions & 1 deletion actions/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { prisma } from "@/db/client";
import { TUser } from "@/types/User";


export const orderHandler = async (user: TUser) => {
if (user && user.basket) {
try {
Expand Down
30 changes: 15 additions & 15 deletions actions/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import { redirect } from "next/navigation";
import { NextResponse } from "next/server";

const getURL = () => {
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
'http://localhost:3000/';

// Make sure to include https:// when not localhost.
url = url.includes('http') ? url : `https://${url}`;
// Make sure to including trailing /.
url = url.charAt(url.length - 1) === '/' ? url : `${url}/`;
return url;
};
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
"http://localhost:3000/";

export const searchHandler = async (formData:FormData) => {
const key = formData.get('searchKey')
return redirect(getURL()+'/search?search='+key)
}
// Make sure to include https:// when not localhost.
url = url.includes("http") ? url : `https://${url}`;
// Make sure to including trailing /.
url = url.charAt(url.length - 1) === "/" ? url : `${url}/`;
return url;
};

export const searchHandler = async (formData: FormData) => {
const key = formData.get("searchKey");
return redirect(getURL() + "/search?search=" + key);
};
30 changes: 14 additions & 16 deletions app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import AboutCtaSection from '@/containers/about-page/cta-section';
import AboutHeroSection from '@/containers/about-page/hero-section';
import AboutMissionSection from '@/containers/about-page/mission-section';
import AboutTeamSection from '@/containers/about-page/team-section';
import React, { FC } from 'react'
import AboutCtaSection from "@/containers/about-page/cta-section";
import AboutHeroSection from "@/containers/about-page/hero-section";
import AboutMissionSection from "@/containers/about-page/mission-section";
import AboutTeamSection from "@/containers/about-page/team-section";
import React, { FC } from "react";

interface AboutProps {

}
interface AboutProps {}

const About: FC<AboutProps> = ({ }) => {
const About: FC<AboutProps> = ({}) => {
return (
<main>
<AboutHeroSection />
<AboutMissionSection />
<AboutTeamSection />
<AboutCtaSection />
<AboutHeroSection />
<AboutMissionSection />
<AboutTeamSection />
<AboutCtaSection />
</main>
)
}
);
};

export default About;
export default About;
21 changes: 10 additions & 11 deletions app/api/products/getAll/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,31 @@ export async function GET(request: NextRequest) {
}
}
export async function POST(request: NextRequest) {
const { page, perItems,sort } = await request.json();
const { page, perItems, sort } = await request.json();

const slicer = (itemsPerPage:number,products:any[]) => {
const slicer = (itemsPerPage: number, products: any[]) => {
const startIndex = (page - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;

if (startIndex >= products.length) {
// Return an empty array if the page is out of bounds
return [];
}

// Slice the products array to get the products for the current page
const pageProducts = products.slice(startIndex, endIndex);

return pageProducts;
}
};
try {
const products = await prisma.product.findMany();
let sorted = products
if(sort==='pricelow'){
let sorted = products;
if (sort === "pricelow") {
sorted = products.sort((a, b) => a.price - b.price);
}else if(sort==='pricehigh'){
} else if (sort === "pricehigh") {
sorted = products.sort((a, b) => b.price - a.price);

}
const res = slicer(perItems,products)
const res = slicer(perItems, products);
return NextResponse.json({ data: res, size: products.length });
} catch (err) {
return NextResponse.error();
Expand Down
39 changes: 18 additions & 21 deletions app/api/products/getSingle/route.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { prisma } from '@/db/client'
import { NextResponse } from 'next/server'
import { prisma } from "@/db/client";
import { NextResponse } from "next/server";

import type { NextRequest } from 'next/server'
import type { NextRequest } from "next/server";

export const dynamic = 'force-dynamic'
export const dynamic = "force-dynamic";

export async function POST(request: NextRequest) {
const {id} = await request.json()
try{

const product = await prisma.product.findUnique({
where: {
id:Number(id)
}
})
console.log(product, 'TARGET PRODUCT')

return NextResponse.json({data:product})

}catch(err){
return NextResponse.error()
}finally{
prisma.$disconnect()
}
const { id } = await request.json();
try {
const product = await prisma.product.findUnique({
where: {
id: Number(id),
},
});
console.log(product, "TARGET PRODUCT");

return NextResponse.json({ data: product });
} catch (err) {
return NextResponse.error();
} finally {
prisma.$disconnect();
}
}
19 changes: 11 additions & 8 deletions app/api/products/searchItem/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
const { key } = await request.json();


try {
const products = await prisma.product.findMany();
let result = []
const searchValue : string = key.toLowerCase()
for(let product of products){
if(Object.values(product).includes(searchValue.charAt(0).toUpperCase()+searchValue.slice(1))){
result.push(product)
}
let result = [];
const searchValue: string = key.toLowerCase();
for (let product of products) {
if (
Object.values(product).includes(
searchValue.charAt(0).toUpperCase() + searchValue.slice(1)
)
) {
result.push(product);
}
}

return NextResponse.json({ data: result});
return NextResponse.json({ data: result });
} catch (err) {
return NextResponse.error();
} finally {
Expand Down
135 changes: 67 additions & 68 deletions app/api/user/basket/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,75 @@ import type { NextRequest } from "next/server";
export const dynamic = "force-dynamic";

export async function POST(request: NextRequest) {
const { action,payload,user,item } = await request.json();
const { action, payload, user, item } = await request.json();

if(action==='add'){
try{
if(user){

const updatedUser = await prisma.user.update({
where:{
email:user.email
},
data:{
basket:[...user.basket,payload]
}
})

const result = await prisma.user.update({
where:{
email:user.email
},
data:{
totalPrice:Number(updatedUser.basket.reduce((acc,curr:any) => acc+curr.item.price,0))
}
})
return NextResponse.json({data:'added',result:result})
}
}catch(err){
console.log(err)
}finally{
prisma.$disconnect()
}

}else if(action==='remove'){

if(user){
const newBasket = user.basket.filter((el:any) => el.id !== item.id)
const updatedUser = await prisma.user.update({
where:{
email:user.email
},
data:{
basket:newBasket
}
})
const result = await prisma.user.update({
where:{
email:user.email
},
data:{
totalPrice:(updatedUser.totalPrice)-(item.item.price)
}
})
return NextResponse.json({data:'added',result:result})
}
return NextResponse.json({data:'removed'})
}else if(action==='wipe'){

if(user){
if (action === "add") {
try {
if (user) {
const updatedUser = await prisma.user.update({
where: {
email: user.email,
},
data: {
basket: [...user.basket, payload],
},
});

const result = await prisma.user.update({
where:{
email:user.email
},
data:{
totalPrice:0,
basket:[]
}
})
return NextResponse.json({data:'added',result:result})
where: {
email: user.email,
},
data: {
totalPrice: Number(
updatedUser.basket.reduce(
(acc, curr: any) => acc + curr.item.price,
0
)
),
},
});
return NextResponse.json({ data: "added", result: result });
}
} catch (err) {
console.log(err);
} finally {
prisma.$disconnect();
}
return NextResponse.json({data:'removed'})
}

} else if (action === "remove") {
if (user) {
const newBasket = user.basket.filter((el: any) => el.id !== item.id);
const updatedUser = await prisma.user.update({
where: {
email: user.email,
},
data: {
basket: newBasket,
},
});
const result = await prisma.user.update({
where: {
email: user.email,
},
data: {
totalPrice: updatedUser.totalPrice - item.item.price,
},
});
return NextResponse.json({ data: "added", result: result });
}
return NextResponse.json({ data: "removed" });
} else if (action === "wipe") {
if (user) {
const result = await prisma.user.update({
where: {
email: user.email,
},
data: {
totalPrice: 0,
basket: [],
},
});
return NextResponse.json({ data: "added", result: result });
}
return NextResponse.json({ data: "removed" });
}
}
Loading

0 comments on commit ec4e7d0

Please sign in to comment.