fix build

This commit is contained in:
Danel Kungla
2025-07-09 14:01:43 +03:00
parent d9198a8a12
commit c5ddccc15d
6 changed files with 152 additions and 134 deletions

View File

@@ -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 (
<form
onSubmit={handleSubmit(onSubmit)}
noValidate
className="flex flex-col gap-6 px-6 pt-8 text-left"
>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:companyName'} />
</Label>
<Input {...register('companyName')} />
</FormItem>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:contactPerson'} />
</Label>
<Input {...register('contactPerson')} />
</FormItem>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:email'} />
</Label>
<Input type="email" {...register('email')}></Input>
</FormItem>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:phone'} />
</Label>
<Input type="tel" {...register('phone')} />
</FormItem>
<SubmitButton
disabled={!isValid || isSubmitting}
pendingText="Saatmine..."
type="submit"
>
<Trans i18nKey={'account:requestCompanyAccount:button'} />
</SubmitButton>
</form>
);
};
export default CompanyOfferForm;

View File

@@ -1,54 +1,13 @@
'use client';
import React from 'react'; import React from 'react';
import { useRouter } from 'next/navigation';
import { MedReportLogo } from '@/components/med-report-logo'; import { MedReportLogo } from '@/components/med-report-logo';
import { SubmitButton } from '@/components/ui/submit-button';
import { withI18n } from '@/lib/i18n/with-i18n'; 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 { Trans } from '@kit/ui/trans';
import CompanyOfferForm from './_components/company-offer-form';
function CompanyOffer() { 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 ( return (
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border"> <div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
<div className="flex w-1/2 flex-col px-12 py-14 text-center"> <div className="flex w-1/2 flex-col px-12 py-14 text-center">
@@ -59,43 +18,7 @@ function CompanyOffer() {
<p className="text-muted-foreground pt-2 text-sm"> <p className="text-muted-foreground pt-2 text-sm">
<Trans i18nKey={'account:requestCompanyAccount:description'} /> <Trans i18nKey={'account:requestCompanyAccount:description'} />
</p> </p>
<form <CompanyOfferForm />
onSubmit={handleSubmit(onSubmit)}
noValidate
className="flex flex-col gap-6 px-6 pt-8 text-left"
>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:companyName'} />
</Label>
<Input {...register('companyName')} />
</FormItem>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:contactPerson'} />
</Label>
<Input {...register('contactPerson')} />
</FormItem>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:email'} />
</Label>
<Input type="email" {...register('email')}></Input>
</FormItem>
<FormItem>
<Label>
<Trans i18nKey={'common:formField:phone'} />
</Label>
<Input type="tel" {...register('phone')} />
</FormItem>
<SubmitButton
disabled={!isValid || isSubmitting}
pendingText="Saatmine..."
type="submit"
>
<Trans i18nKey={'account:requestCompanyAccount:button'} />
</SubmitButton>
</form>
</div> </div>
<div className="w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat"></div> <div className="w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat"></div>
</div> </div>

View File

@@ -139,7 +139,7 @@ function getPatterns() {
handler: adminMiddleware, handler: adminMiddleware,
}, },
{ {
pattern: new URLPattern({ pathname: '/auth/*?' }), pattern: new URLPattern({ pathname: '/auth/update-account' }),
handler: async (req: NextRequest, res: NextResponse) => { handler: async (req: NextRequest, res: NextResponse) => {
const { const {
data: { user }, data: { user },

View File

@@ -1,25 +1,27 @@
import { deleteLineItem } from "@lib/data/cart" "use client";
import { Spinner, Trash } from "@medusajs/icons"
import { clx } from "@medusajs/ui" import { deleteLineItem } from "@lib/data/cart";
import { useState } from "react" import { Spinner, Trash } from "@medusajs/icons";
import { clx } from "@medusajs/ui";
import { useState } from "react";
const DeleteButton = ({ const DeleteButton = ({
id, id,
children, children,
className, className,
}: { }: {
id: string id: string;
children?: React.ReactNode children?: React.ReactNode;
className?: string className?: string;
}) => { }) => {
const [isDeleting, setIsDeleting] = useState(false) const [isDeleting, setIsDeleting] = useState(false);
const handleDelete = async (id: string) => { const handleDelete = async (id: string) => {
setIsDeleting(true) setIsDeleting(true);
await deleteLineItem(id).catch((err) => { await deleteLineItem(id).catch((err) => {
setIsDeleting(false) setIsDeleting(false);
}) });
} };
return ( return (
<div <div
@@ -36,7 +38,7 @@ const DeleteButton = ({
<span>{children}</span> <span>{children}</span>
</button> </button>
</div> </div>
) );
} };
export default DeleteButton export default DeleteButton;

View File

@@ -1,37 +1,39 @@
import { Label } from "@medusajs/ui" "use client";
import React, { useEffect, useImperativeHandle, useState } from "react"
import Eye from "@modules/common/icons/eye" import { Label } from "@medusajs/ui";
import EyeOff from "@modules/common/icons/eye-off" 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< type InputProps = Omit<
Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">, Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
"placeholder" "placeholder"
> & { > & {
label: string label: string;
errors?: Record<string, unknown> errors?: Record<string, unknown>;
touched?: Record<string, unknown> touched?: Record<string, unknown>;
name: string name: string;
topLabel?: string topLabel?: string;
} };
const Input = React.forwardRef<HTMLInputElement, InputProps>( const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ type, name, label, touched, required, topLabel, ...props }, ref) => { ({ type, name, label, touched, required, topLabel, ...props }, ref) => {
const inputRef = React.useRef<HTMLInputElement>(null) const inputRef = React.useRef<HTMLInputElement>(null);
const [showPassword, setShowPassword] = useState(false) const [showPassword, setShowPassword] = useState(false);
const [inputType, setInputType] = useState(type) const [inputType, setInputType] = useState(type);
useEffect(() => { useEffect(() => {
if (type === "password" && showPassword) { if (type === "password" && showPassword) {
setInputType("text") setInputType("text");
} }
if (type === "password" && !showPassword) { if (type === "password" && !showPassword) {
setInputType("password") setInputType("password");
} }
}, [type, showPassword]) }, [type, showPassword]);
useImperativeHandle(ref, () => inputRef.current!) useImperativeHandle(ref, () => inputRef.current!);
return ( return (
<div className="flex flex-col w-full"> <div className="flex flex-col w-full">
@@ -67,10 +69,10 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
)} )}
</div> </div>
</div> </div>
) );
} }
) );
Input.displayName = "Input" Input.displayName = "Input";
export default Input export default Input;

View File

@@ -1,5 +1,7 @@
import { ChevronUpDown } from "@medusajs/icons" "use client";
import { clx } from "@medusajs/ui"
import { ChevronUpDown } from "@medusajs/icons";
import { clx } from "@medusajs/ui";
import { import {
SelectHTMLAttributes, SelectHTMLAttributes,
forwardRef, forwardRef,
@@ -7,34 +9,34 @@ import {
useImperativeHandle, useImperativeHandle,
useRef, useRef,
useState, useState,
} from "react" } from "react";
export type NativeSelectProps = { export type NativeSelectProps = {
placeholder?: string placeholder?: string;
errors?: Record<string, unknown> errors?: Record<string, unknown>;
touched?: Record<string, unknown> touched?: Record<string, unknown>;
} & SelectHTMLAttributes<HTMLSelectElement> } & SelectHTMLAttributes<HTMLSelectElement>;
const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>( const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>(
( (
{ placeholder = "Select...", defaultValue, className, children, ...props }, { placeholder = "Select...", defaultValue, className, children, ...props },
ref ref
) => { ) => {
const innerRef = useRef<HTMLSelectElement>(null) const innerRef = useRef<HTMLSelectElement>(null);
const [isPlaceholder, setIsPlaceholder] = useState(false) const [isPlaceholder, setIsPlaceholder] = useState(false);
useImperativeHandle<HTMLSelectElement | null, HTMLSelectElement | null>( useImperativeHandle<HTMLSelectElement | null, HTMLSelectElement | null>(
ref, ref,
() => innerRef.current () => innerRef.current
) );
useEffect(() => { useEffect(() => {
if (innerRef.current && innerRef.current.value === "") { if (innerRef.current && innerRef.current.value === "") {
setIsPlaceholder(true) setIsPlaceholder(true);
} else { } else {
setIsPlaceholder(false) setIsPlaceholder(false);
} }
}, [innerRef.current?.value]) }, [innerRef.current?.value]);
return ( return (
<div> <div>
@@ -65,10 +67,10 @@ const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>(
</span> </span>
</div> </div>
</div> </div>
) );
} }
) );
NativeSelect.displayName = "NativeSelect" NativeSelect.displayName = "NativeSelect";
export default NativeSelect export default NativeSelect;