From 5fa54750637a306e00f8b02ac893da08228e7342 Mon Sep 17 00:00:00 2001 From: david emioma Date: Tue, 14 May 2024 02:31:14 +0100 Subject: [PATCH] Some UI updates --- app/(marketing)/page.tsx | 2 +- .../products/_components/ProductForm.tsx | 41 ++++++++- .../[storeId]/products/[productId]/route.ts | 27 ------ .../stores/[storeId]/products/new/route.ts | 27 ------ package-lock.json | 88 +++++++++---------- package.json | 2 +- 6 files changed, 83 insertions(+), 104 deletions(-) diff --git a/app/(marketing)/page.tsx b/app/(marketing)/page.tsx index 1e7c6e0..e53aedc 100644 --- a/app/(marketing)/page.tsx +++ b/app/(marketing)/page.tsx @@ -21,7 +21,7 @@ export default async function Home() {

- High-Quality Products{" "} + High-Quality Products{" "} You Can Trust, Every Time.

diff --git a/app/(store)/dashboard/[storeId]/products/_components/ProductForm.tsx b/app/(store)/dashboard/[storeId]/products/_components/ProductForm.tsx index 4ba88e8..1afd693 100644 --- a/app/(store)/dashboard/[storeId]/products/_components/ProductForm.tsx +++ b/app/(store)/dashboard/[storeId]/products/_components/ProductForm.tsx @@ -9,8 +9,10 @@ import AvailableForm from "./AvailableForm"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import BtnSpinner from "@/components/BtnSpinner"; +import { checkImage } from "@/actions/checkImage"; import ImageUpload from "@/components/ImageUpload"; import MultiSelect from "@/components/MultiSelect"; +import { Textarea } from "@/components/ui/textarea"; import { zodResolver } from "@hookform/resolvers/zod"; import { useParams, useRouter } from "next/navigation"; import ColorModal from "@/components/modal/ColorModal"; @@ -42,7 +44,6 @@ import { FormItem, FormMessage, } from "@/components/ui/form"; -import { Textarea } from "@/components/ui/textarea"; type ProductItemType = ProductItem & { availableItems: Available[]; @@ -171,13 +172,37 @@ const ProductForm = ({ data }: Props) => { }, }); + const checkProductImages = async (values: ProductValidator) => { + if (process.env.VERCEL_ENV !== "production") { + return false; + } + + let hasInappropriateImages = false; + + await Promise.all( + values.productItems.map(async (item) => { + await Promise.all( + item.images.map(async (imageUrl) => { + const imgIsAppropiate = await checkImage({ imageUrl }); + + if (!imgIsAppropiate.isAppropiate || imgIsAppropiate.error) { + hasInappropriateImages = true; + } + }) + ); + }) + ); + + return hasInappropriateImages; + }; + const { mutate: createProduct, isPending: creating } = useMutation({ mutationKey: ["create-product"], mutationFn: async (values: ProductValidator) => { await axios.post(`/api/stores/${params.storeId}/products/new`, values); }, onSuccess: () => { - toast.success(data ? "Product Updated!" : "Product Created!"); + toast.success("Product Created!"); router.push(`/dashboard/${params.storeId}/products`); @@ -203,7 +228,7 @@ const ProductForm = ({ data }: Props) => { ); }, onSuccess: () => { - toast.success(data ? "Product Updated!" : "Product Created!"); + toast.success("Product Updated!"); router.refresh(); }, @@ -216,9 +241,17 @@ const ProductForm = ({ data }: Props) => { }, }); - const onSubmit = (values: ProductValidator) => { + const onSubmit = async (values: ProductValidator) => { if (honeyPot) return; + const imagesAreInappropiate = await checkProductImages(values); + + if (imagesAreInappropiate) { + toast.error("The images of your product is inappropiate! Change it."); + + return; + } + if (data) { updateProduct(values); } else { diff --git a/app/api/stores/[storeId]/products/[productId]/route.ts b/app/api/stores/[storeId]/products/[productId]/route.ts index ba81674..ad623c1 100644 --- a/app/api/stores/[storeId]/products/[productId]/route.ts +++ b/app/api/stores/[storeId]/products/[productId]/route.ts @@ -3,7 +3,6 @@ import { apiRatelimit } from "@/lib/redis"; import { NextResponse } from "next/server"; import { getCurrentPrice } from "@/lib/utils"; import { checkText } from "@/actions/checkText"; -import { checkImage } from "@/actions/checkImage"; import { currentRole, currentUser } from "@/lib/auth"; import { UserRole, storeStatus } from "@prisma/client"; import { ProductSchema } from "@/lib/validators/product"; @@ -115,32 +114,6 @@ export async function PATCH( } ); } - - //Check if images are appropiate - let hasInappropriateImages = false; - - await Promise.all( - productItems.map(async (item) => { - await Promise.all( - item.images.map(async (imageUrl) => { - const imgIsAppropiate = await checkImage({ imageUrl }); - - if (!imgIsAppropiate.isAppropiate || imgIsAppropiate.error) { - hasInappropriateImages = true; - } - }) - ); - }) - ); - - if (hasInappropriateImages) { - return new NextResponse( - "The images of your product is inappropiate! Change it.", - { - status: 400, - } - ); - } } //Check if product exists diff --git a/app/api/stores/[storeId]/products/new/route.ts b/app/api/stores/[storeId]/products/new/route.ts index 25da0ff..4d1e20a 100644 --- a/app/api/stores/[storeId]/products/new/route.ts +++ b/app/api/stores/[storeId]/products/new/route.ts @@ -3,7 +3,6 @@ import { apiRatelimit } from "@/lib/redis"; import { NextResponse } from "next/server"; import { getCurrentPrice } from "@/lib/utils"; import { checkText } from "@/actions/checkText"; -import { checkImage } from "@/actions/checkImage"; import { sendCreatedProductEmail } from "@/lib/mail"; import { UserRole, storeStatus } from "@prisma/client"; import { currentRole, currentUser } from "@/lib/auth"; @@ -110,32 +109,6 @@ export async function POST( } ); } - - //Check if images are appropiate - let hasInappropriateImages = false; - - await Promise.all( - productItems.map(async (item) => { - await Promise.all( - item.images.map(async (imageUrl) => { - const imgIsAppropiate = await checkImage({ imageUrl }); - - if (!imgIsAppropiate.isAppropiate || imgIsAppropiate.error) { - hasInappropriateImages = true; - } - }) - ); - }) - ); - - if (hasInappropriateImages) { - return new NextResponse( - "The images of your product is inappropiate! Change it.", - { - status: 400, - } - ); - } } //Create Product diff --git a/package-lock.json b/package-lock.json index ea7de63..2c7f3dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,7 @@ "input-otp": "^1.2.4", "lodash.debounce": "^4.0.8", "lucide-react": "^0.319.0", - "next": "14.1.0", + "next": "14.1.1", "next-auth": "^5.0.0-beta.4", "node-fetch": "^3.3.2", "nodemailer": "^6.9.9", @@ -3251,9 +3251,9 @@ } }, "node_modules/@next/env": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.1.0.tgz", - "integrity": "sha512-Py8zIo+02ht82brwwhTg36iogzFqGLPXlRGKQw5s+qP/kMNc4MAyDeEwBKDijk6zTIbegEgu8Qy7C1LboslQAw==" + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.1.1.tgz", + "integrity": "sha512-7CnQyD5G8shHxQIIg3c7/pSeYFeMhsNbpU/bmvH7ZnDql7mNRgg8O2JZrhrc/soFnfBnKP4/xXNiiSIPn2w8gA==" }, "node_modules/@next/eslint-plugin-next": { "version": "14.1.0", @@ -3265,9 +3265,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.1.0.tgz", - "integrity": "sha512-nUDn7TOGcIeyQni6lZHfzNoo9S0euXnu0jhsbMOmMJUBfgsnESdjN97kM7cBqQxZa8L/bM9om/S5/1dzCrW6wQ==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.1.1.tgz", + "integrity": "sha512-yDjSFKQKTIjyT7cFv+DqQfW5jsD+tVxXTckSe1KIouKk75t1qZmj/mV3wzdmFb0XHVGtyRjDMulfVG8uCKemOQ==", "cpu": [ "arm64" ], @@ -3280,9 +3280,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.1.0.tgz", - "integrity": "sha512-1jgudN5haWxiAl3O1ljUS2GfupPmcftu2RYJqZiMJmmbBT5M1XDffjUtRUzP4W3cBHsrvkfOFdQ71hAreNQP6g==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.1.1.tgz", + "integrity": "sha512-KCQmBL0CmFmN8D64FHIZVD9I4ugQsDBBEJKiblXGgwn7wBCSe8N4Dx47sdzl4JAg39IkSN5NNrr8AniXLMb3aw==", "cpu": [ "x64" ], @@ -3295,9 +3295,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.1.0.tgz", - "integrity": "sha512-RHo7Tcj+jllXUbK7xk2NyIDod3YcCPDZxj1WLIYxd709BQ7WuRYl3OWUNG+WUfqeQBds6kvZYlc42NJJTNi4tQ==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.1.1.tgz", + "integrity": "sha512-YDQfbWyW0JMKhJf/T4eyFr4b3tceTorQ5w2n7I0mNVTFOvu6CGEzfwT3RSAQGTi/FFMTFcuspPec/7dFHuP7Eg==", "cpu": [ "arm64" ], @@ -3310,9 +3310,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.1.0.tgz", - "integrity": "sha512-v6kP8sHYxjO8RwHmWMJSq7VZP2nYCkRVQ0qolh2l6xroe9QjbgV8siTbduED4u0hlk0+tjS6/Tuy4n5XCp+l6g==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.1.1.tgz", + "integrity": "sha512-fiuN/OG6sNGRN/bRFxRvV5LyzLB8gaL8cbDH5o3mEiVwfcMzyE5T//ilMmaTrnA8HLMS6hoz4cHOu6Qcp9vxgQ==", "cpu": [ "arm64" ], @@ -3325,9 +3325,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.1.0.tgz", - "integrity": "sha512-zJ2pnoFYB1F4vmEVlb/eSe+VH679zT1VdXlZKX+pE66grOgjmKJHKacf82g/sWE4MQ4Rk2FMBCRnX+l6/TVYzQ==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.1.1.tgz", + "integrity": "sha512-rv6AAdEXoezjbdfp3ouMuVqeLjE1Bin0AuE6qxE6V9g3Giz5/R3xpocHoAi7CufRR+lnkuUjRBn05SYJ83oKNQ==", "cpu": [ "x64" ], @@ -3340,9 +3340,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.1.0.tgz", - "integrity": "sha512-rbaIYFt2X9YZBSbH/CwGAjbBG2/MrACCVu2X0+kSykHzHnYH5FjHxwXLkcoJ10cX0aWCEynpu+rP76x0914atg==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.1.1.tgz", + "integrity": "sha512-YAZLGsaNeChSrpz/G7MxO3TIBLaMN8QWMr3X8bt6rCvKovwU7GqQlDu99WdvF33kI8ZahvcdbFsy4jAFzFX7og==", "cpu": [ "x64" ], @@ -3355,9 +3355,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.1.0.tgz", - "integrity": "sha512-o1N5TsYc8f/HpGt39OUQpQ9AKIGApd3QLueu7hXk//2xq5Z9OxmV6sQfNp8C7qYmiOlHYODOGqNNa0e9jvchGQ==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.1.1.tgz", + "integrity": "sha512-1L4mUYPBMvVDMZg1inUYyPvFSduot0g73hgfD9CODgbr4xiTYe0VOMTZzaRqYJYBA9mana0x4eaAaypmWo1r5A==", "cpu": [ "arm64" ], @@ -3370,9 +3370,9 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.1.0.tgz", - "integrity": "sha512-XXIuB1DBRCFwNO6EEzCTMHT5pauwaSj4SWs7CYnME57eaReAKBXCnkUE80p/pAZcewm7hs+vGvNqDPacEXHVkw==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.1.1.tgz", + "integrity": "sha512-jvIE9tsuj9vpbbXlR5YxrghRfMuG0Qm/nZ/1KDHc+y6FpnZ/apsgh+G6t15vefU0zp3WSpTMIdXRUsNl/7RSuw==", "cpu": [ "ia32" ], @@ -3385,9 +3385,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.1.0.tgz", - "integrity": "sha512-9WEbVRRAqJ3YFVqEZIxUqkiO8l1nool1LmNxygr5HWF8AcSYsEpneUDhmjUVJEzO2A04+oPtZdombzzPPkTtgg==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.1.1.tgz", + "integrity": "sha512-S6K6EHDU5+1KrBDLko7/c1MNy/Ya73pIAmvKeFwsF4RmBFJSO7/7YeD4FnZ4iBdzE69PpQ4sOMU9ORKeNuxe8A==", "cpu": [ "x64" ], @@ -12402,11 +12402,11 @@ "dev": true }, "node_modules/next": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/next/-/next-14.1.0.tgz", - "integrity": "sha512-wlzrsbfeSU48YQBjZhDzOwhWhGsy+uQycR8bHAOt1LY1bn3zZEcDyHQOEoN3aWzQ8LHCAJ1nqrWCc9XF2+O45Q==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/next/-/next-14.1.1.tgz", + "integrity": "sha512-McrGJqlGSHeaz2yTRPkEucxQKe5Zq7uPwyeHNmJaZNY4wx9E9QdxmTp310agFRoMuIYgQrCrT3petg13fSVOww==", "dependencies": { - "@next/env": "14.1.0", + "@next/env": "14.1.1", "@swc/helpers": "0.5.2", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", @@ -12421,15 +12421,15 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.1.0", - "@next/swc-darwin-x64": "14.1.0", - "@next/swc-linux-arm64-gnu": "14.1.0", - "@next/swc-linux-arm64-musl": "14.1.0", - "@next/swc-linux-x64-gnu": "14.1.0", - "@next/swc-linux-x64-musl": "14.1.0", - "@next/swc-win32-arm64-msvc": "14.1.0", - "@next/swc-win32-ia32-msvc": "14.1.0", - "@next/swc-win32-x64-msvc": "14.1.0" + "@next/swc-darwin-arm64": "14.1.1", + "@next/swc-darwin-x64": "14.1.1", + "@next/swc-linux-arm64-gnu": "14.1.1", + "@next/swc-linux-arm64-musl": "14.1.1", + "@next/swc-linux-x64-gnu": "14.1.1", + "@next/swc-linux-x64-musl": "14.1.1", + "@next/swc-win32-arm64-msvc": "14.1.1", + "@next/swc-win32-ia32-msvc": "14.1.1", + "@next/swc-win32-x64-msvc": "14.1.1" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", diff --git a/package.json b/package.json index 08c01e5..60cd709 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "input-otp": "^1.2.4", "lodash.debounce": "^4.0.8", "lucide-react": "^0.319.0", - "next": "14.1.0", + "next": "14.1.1", "next-auth": "^5.0.0-beta.4", "node-fetch": "^3.3.2", "nodemailer": "^6.9.9",