From c5ddccc15d2cabff7bdfa6157ed99d2754c113d4 Mon Sep 17 00:00:00 2001 From: Danel Kungla Date: Wed, 9 Jul 2025 14:01:43 +0300 Subject: [PATCH] fix build --- .../_components/company-offer-form.tsx | 89 +++++++++++++++++++ app/(public)/company-offer/page.tsx | 83 +---------------- middleware.ts | 2 +- .../common/components/delete-button/index.tsx | 32 +++---- .../modules/common/components/input/index.tsx | 44 ++++----- .../common/components/native-select/index.tsx | 36 ++++---- 6 files changed, 152 insertions(+), 134 deletions(-) create mode 100644 app/(public)/company-offer/_components/company-offer-form.tsx diff --git a/app/(public)/company-offer/_components/company-offer-form.tsx b/app/(public)/company-offer/_components/company-offer-form.tsx new file mode 100644 index 0000000..328caaf --- /dev/null +++ b/app/(public)/company-offer/_components/company-offer-form.tsx @@ -0,0 +1,89 @@ +'use client'; + +import { useRouter } from 'next/navigation'; + +import { SubmitButton } from '@/components/ui/submit-button'; +import { sendCompanyOfferEmail } from '@/lib/services/mailer.service'; +import { CompanySubmitData } from '@/lib/types/company'; +import { companyOfferSchema } from '@/lib/validations/company-offer.schema'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { useTranslation } from 'react-i18next'; + +import { FormItem } from '@kit/ui/form'; +import { Input } from '@kit/ui/input'; +import { Label } from '@kit/ui/label'; +import { Trans } from '@kit/ui/trans'; + +const CompanyOfferForm = () => { + const router = useRouter(); + const language = useTranslation().i18n.language; + const { + register, + handleSubmit, + formState: { isValid, isSubmitting }, + } = useForm({ + resolver: zodResolver(companyOfferSchema), + mode: 'onChange', + }); + + const onSubmit = async (data: CompanySubmitData) => { + const formData = new FormData(); + Object.entries(data).forEach(([key, value]) => { + if (value !== undefined) formData.append(key, value); + }); + + try { + sendCompanyOfferEmail(data, language) + .then(() => router.push('/company-offer/success')) + .catch((error) => alert('error: ' + error)); + } catch (err: unknown) { + if (err instanceof Error) { + console.warn('Server validation error: ' + err.message); + } + console.warn('Server validation error: ', err); + } + }; + + return ( +
+ + + + + + + + + + + + + + + + + + + +
+ ); +}; + +export default CompanyOfferForm; diff --git a/app/(public)/company-offer/page.tsx b/app/(public)/company-offer/page.tsx index 4f293e5..01f46b1 100644 --- a/app/(public)/company-offer/page.tsx +++ b/app/(public)/company-offer/page.tsx @@ -1,54 +1,13 @@ -'use client'; - import React from 'react'; -import { useRouter } from 'next/navigation'; - import { MedReportLogo } from '@/components/med-report-logo'; -import { SubmitButton } from '@/components/ui/submit-button'; import { withI18n } from '@/lib/i18n/with-i18n'; -import { sendCompanyOfferEmail } from '@/lib/services/mailer.service'; -import { CompanySubmitData } from '@/lib/types/company'; -import { companyOfferSchema } from '@/lib/validations/company-offer.schema'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { useForm } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { FormItem } from '@kit/ui/form'; -import { Input } from '@kit/ui/input'; -import { Label } from '@kit/ui/label'; import { Trans } from '@kit/ui/trans'; +import CompanyOfferForm from './_components/company-offer-form'; + function CompanyOffer() { - const router = useRouter(); - const { - register, - handleSubmit, - formState: { isValid, isSubmitting }, - } = useForm({ - resolver: zodResolver(companyOfferSchema), - mode: 'onChange', - }); - const language = useTranslation().i18n.language; - - const onSubmit = async (data: CompanySubmitData) => { - const formData = new FormData(); - Object.entries(data).forEach(([key, value]) => { - if (value !== undefined) formData.append(key, value); - }); - - try { - sendCompanyOfferEmail(data, language) - .then(() => router.push('/company-offer/success')) - .catch((error) => alert('error: ' + error)); - } catch (err: unknown) { - if (err instanceof Error) { - console.warn('Server validation error: ' + err.message); - } - console.warn('Server validation error: ', err); - } - }; - return (
@@ -59,43 +18,7 @@ function CompanyOffer() {

-
- - - - - - - - - - - - - - - - - - - -
+
diff --git a/middleware.ts b/middleware.ts index 1739283..c9283b7 100644 --- a/middleware.ts +++ b/middleware.ts @@ -139,7 +139,7 @@ function getPatterns() { handler: adminMiddleware, }, { - pattern: new URLPattern({ pathname: '/auth/*?' }), + pattern: new URLPattern({ pathname: '/auth/update-account' }), handler: async (req: NextRequest, res: NextResponse) => { const { data: { user }, diff --git a/packages/features/medusa-storefront/src/modules/common/components/delete-button/index.tsx b/packages/features/medusa-storefront/src/modules/common/components/delete-button/index.tsx index ba1be22..161e0d6 100644 --- a/packages/features/medusa-storefront/src/modules/common/components/delete-button/index.tsx +++ b/packages/features/medusa-storefront/src/modules/common/components/delete-button/index.tsx @@ -1,25 +1,27 @@ -import { deleteLineItem } from "@lib/data/cart" -import { Spinner, Trash } from "@medusajs/icons" -import { clx } from "@medusajs/ui" -import { useState } from "react" +"use client"; + +import { deleteLineItem } from "@lib/data/cart"; +import { Spinner, Trash } from "@medusajs/icons"; +import { clx } from "@medusajs/ui"; +import { useState } from "react"; const DeleteButton = ({ id, children, className, }: { - id: string - children?: React.ReactNode - className?: string + id: string; + children?: React.ReactNode; + className?: string; }) => { - const [isDeleting, setIsDeleting] = useState(false) + const [isDeleting, setIsDeleting] = useState(false); const handleDelete = async (id: string) => { - setIsDeleting(true) + setIsDeleting(true); await deleteLineItem(id).catch((err) => { - setIsDeleting(false) - }) - } + setIsDeleting(false); + }); + }; return (
{children}
- ) -} + ); +}; -export default DeleteButton +export default DeleteButton; diff --git a/packages/features/medusa-storefront/src/modules/common/components/input/index.tsx b/packages/features/medusa-storefront/src/modules/common/components/input/index.tsx index 1234ebb..0ebadfb 100644 --- a/packages/features/medusa-storefront/src/modules/common/components/input/index.tsx +++ b/packages/features/medusa-storefront/src/modules/common/components/input/index.tsx @@ -1,37 +1,39 @@ -import { Label } from "@medusajs/ui" -import React, { useEffect, useImperativeHandle, useState } from "react" +"use client"; -import Eye from "@modules/common/icons/eye" -import EyeOff from "@modules/common/icons/eye-off" +import { Label } from "@medusajs/ui"; +import React, { useEffect, useImperativeHandle, useState } from "react"; + +import Eye from "@modules/common/icons/eye"; +import EyeOff from "@modules/common/icons/eye-off"; type InputProps = Omit< Omit, "size">, "placeholder" > & { - label: string - errors?: Record - touched?: Record - name: string - topLabel?: string -} + label: string; + errors?: Record; + touched?: Record; + name: string; + topLabel?: string; +}; const Input = React.forwardRef( ({ type, name, label, touched, required, topLabel, ...props }, ref) => { - const inputRef = React.useRef(null) - const [showPassword, setShowPassword] = useState(false) - const [inputType, setInputType] = useState(type) + const inputRef = React.useRef(null); + const [showPassword, setShowPassword] = useState(false); + const [inputType, setInputType] = useState(type); useEffect(() => { if (type === "password" && showPassword) { - setInputType("text") + setInputType("text"); } if (type === "password" && !showPassword) { - setInputType("password") + setInputType("password"); } - }, [type, showPassword]) + }, [type, showPassword]); - useImperativeHandle(ref, () => inputRef.current!) + useImperativeHandle(ref, () => inputRef.current!); return (
@@ -67,10 +69,10 @@ const Input = React.forwardRef( )}
- ) + ); } -) +); -Input.displayName = "Input" +Input.displayName = "Input"; -export default Input +export default Input; diff --git a/packages/features/medusa-storefront/src/modules/common/components/native-select/index.tsx b/packages/features/medusa-storefront/src/modules/common/components/native-select/index.tsx index 40ee68d..70eaed3 100644 --- a/packages/features/medusa-storefront/src/modules/common/components/native-select/index.tsx +++ b/packages/features/medusa-storefront/src/modules/common/components/native-select/index.tsx @@ -1,5 +1,7 @@ -import { ChevronUpDown } from "@medusajs/icons" -import { clx } from "@medusajs/ui" +"use client"; + +import { ChevronUpDown } from "@medusajs/icons"; +import { clx } from "@medusajs/ui"; import { SelectHTMLAttributes, forwardRef, @@ -7,34 +9,34 @@ import { useImperativeHandle, useRef, useState, -} from "react" +} from "react"; export type NativeSelectProps = { - placeholder?: string - errors?: Record - touched?: Record -} & SelectHTMLAttributes + placeholder?: string; + errors?: Record; + touched?: Record; +} & SelectHTMLAttributes; const NativeSelect = forwardRef( ( { placeholder = "Select...", defaultValue, className, children, ...props }, ref ) => { - const innerRef = useRef(null) - const [isPlaceholder, setIsPlaceholder] = useState(false) + const innerRef = useRef(null); + const [isPlaceholder, setIsPlaceholder] = useState(false); useImperativeHandle( ref, () => innerRef.current - ) + ); useEffect(() => { if (innerRef.current && innerRef.current.value === "") { - setIsPlaceholder(true) + setIsPlaceholder(true); } else { - setIsPlaceholder(false) + setIsPlaceholder(false); } - }, [innerRef.current?.value]) + }, [innerRef.current?.value]); return (
@@ -65,10 +67,10 @@ const NativeSelect = forwardRef(
- ) + ); } -) +); -NativeSelect.displayName = "NativeSelect" +NativeSelect.displayName = "NativeSelect"; -export default NativeSelect +export default NativeSelect;