Skip to content

Commit

Permalink
Some UI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
david emioma committed May 14, 2024
1 parent a2d4a5e commit 5fa5475
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 104 deletions.
2 changes: 1 addition & 1 deletion app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function Home() {
<Container>
<div className="w-full max-w-3xl mx-auto flex flex-col items-center gap-6 text-center">
<h1 className="text-4xl sm:text-6xl text-gray-900 font-bold tracking-tight">
High-Quality <span className="text-green-500">Products</span>{" "}
High-Quality <span className="text-violet-500">Products</span>{" "}
You Can Trust, Every Time.
</h1>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -42,7 +44,6 @@ import {
FormItem,
FormMessage,
} from "@/components/ui/form";
import { Textarea } from "@/components/ui/textarea";

type ProductItemType = ProductItem & {
availableItems: Available[];
Expand Down Expand Up @@ -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`);

Expand All @@ -203,7 +228,7 @@ const ProductForm = ({ data }: Props) => {
);
},
onSuccess: () => {
toast.success(data ? "Product Updated!" : "Product Created!");
toast.success("Product Updated!");

router.refresh();
},
Expand All @@ -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 {
Expand Down
27 changes: 0 additions & 27 deletions app/api/stores/[storeId]/products/[productId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions app/api/stores/[storeId]/products/new/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
88 changes: 44 additions & 44 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5fa5475

Please sign in to comment.