From 936d6410901dc8ffe3364fab3a79e2ce3cb9de7c Mon Sep 17 00:00:00 2001 From: "Puzio, Wojciech" Date: Fri, 12 Jan 2024 17:11:18 +0100 Subject: [PATCH] feat(app) refactor and add components for nice edit --- src/app/dodajProdukt/page.tsx | 108 ++++-------------- src/app/edycjaProduktu/page.tsx | 64 +---------- src/app/usunProdukt/page.tsx | 1 - src/components/CustomInput/CustomInput.tsx | 4 +- src/components/CustomInput/ICustomInput.ts | 8 +- .../CustomTextarea/CustomtextArea.tsx | 2 +- .../CustomUploadCarousel.tsx | 49 ++++++++ .../CutomDropZone/CustomDropZone.tsx | 40 +++++++ src/components/LoginModal/LoginModal.tsx | 10 +- src/components/ProductCard/ProductCard.tsx | 3 +- src/components/StickyNavbar/StickyNavbar.tsx | 25 +--- src/providers/Provider.tsx | 2 +- src/providers/axios-client.ts | 3 +- 13 files changed, 136 insertions(+), 183 deletions(-) create mode 100644 src/components/CustomUploadCarousel/CustomUploadCarousel.tsx create mode 100644 src/components/CutomDropZone/CustomDropZone.tsx diff --git a/src/app/dodajProdukt/page.tsx b/src/app/dodajProdukt/page.tsx index cb10551..f433c5c 100644 --- a/src/app/dodajProdukt/page.tsx +++ b/src/app/dodajProdukt/page.tsx @@ -1,22 +1,15 @@ 'use client'; import { useState } from 'react'; import { AdjustmentsVerticalIcon, CurrencyDollarIcon } from '@heroicons/react/24/solid'; -import { ErrorMessage, Form, Formik } from 'formik'; +import { Form, Formik } from 'formik'; import * as Yup from 'yup'; -import Image from 'next/image'; -import { - Alert, - Button, - Card, - Carousel, - Textarea, - Typography, -} from '@material-tailwind/react'; +import { Alert, Button, Card, Typography } from '@material-tailwind/react'; -import CustomArrow from '@/components/CustomArrow/CustomArrow'; import CustomInput from '@/components/CustomInput/CustomInput'; -import UploadIcon from '@/dodajProdukt/UploadIcon'; +import CustomTextarea from '@/components/CustomTextarea/CustomtextArea'; +import CustomUploadCarousel from '@/components/CustomUploadCarousel/CustomUploadCarousel'; +import CustomDropZone from '@/components/CutomDropZone/CustomDropZone'; import ApiClient from '@/providers/axios-client'; const ProductSchema = Yup.object().shape({ @@ -24,6 +17,17 @@ const ProductSchema = Yup.object().shape({ body: Yup.string().required('Opis produktu jest wymagany'), price: Yup.number().positive('Cena musi być liczbą dodatnią').required('Cena jest wymagana'), amount: Yup.number().positive('Ilość musi być liczbą dodatnią').required('Ilość jest wymagana'), + image: Yup.mixed() + .test('fileSize', 'Plik jest zbyt duży. Maksymalny rozmiar to 800x400px.', (value) => { + if (!value) return true; + // @ts-ignore + return value.size <= 800 * 400; + }) + .test('fileType', 'Dozwolone formaty plików to JPG, PNG, SVG, GIF.', (value) => { + if (!value) return true; + // @ts-ignore + return ['image/jpeg', 'image/png', 'image/svg+xml', 'image/gif'].includes(value.type); + }), }); export default function Home() { @@ -75,16 +79,16 @@ export default function Home() { setSubmissionStatus('success'); resetForm(); setImagePreviews([]); + return response; } catch (error) { setSubmissionStatus('error'); - console.error('Error:', error); } finally { setSubmitting(false); } }} > {({ setFieldValue, isSubmitting, handleChange, values, handleBlur }) => ( -
+
-