'use client' import React from 'react' import MultiSelect from '@/components/ui/Selector' import TextInput from '@/components/ui/TextInput' import PhoneInput from '@/components/ui/PhoneInput' import Button from '@/components/ui/Button' import TextAreaInput from '@/components/ui/TextAreaInput' import CheckboxInput from '@/components/ui/CheckboxInput' import { useForm } from '@/app/hooks/useForm' import showToast from '@/components/ui/Toast' import { SenderPageProps, SelectOption } from '@/app/types' import { cargo_types, cargo_type_translations, transport_types, transport_translations, } from '@/app/constants' const formatDateToHTML = (date: Date) => { const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') const hours = String(date.getHours()).padStart(2, '0') const minutes = String(date.getMinutes()).padStart(2, '0') return `${year}-${month}-${day}T${hours}:${minutes}` } const validationRules = { transport: { required: true }, country_from: { required: true, minLength: 2 }, city_from: { required: true, minLength: 2 }, country_to: { required: true, minLength: 2 }, city_to: { required: true, minLength: 2 }, cargo_type: { required: true }, departure: { required: true, pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/, }, arrival: { required: true, pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/, }, contact_number: { required: true, minLength: 11, pattern: /^\+?[0-9]{11,}$/, }, comment: { required: false, minLength: 10 }, email_notification: { required: false }, } const SenderPage = () => { const today = formatDateToHTML(new Date()) const initialValues: SenderPageProps = { transport: '', country_from: '', city_from: '', country_to: '', city_to: '', cargo_type: '', departure: '', arrival: '', contact_number: '', comment: '', email_notification: false, } const cargoOptions: SelectOption[] = cargo_types.map((type, index) => ({ id: index + 1, label: cargo_type_translations[type], value: type, })) const transportOptions: SelectOption[] = transport_types.map((type, index) => ({ id: index + 1, label: transport_translations[type], value: type, })) const { values, handleChange, handleSubmit } = useForm( initialValues, validationRules, async values => { try { // await addNewSpecialist(values, selectedImage || undefined) showToast({ type: 'success', message: 'Маршрут успешно создан!', }) } catch { showToast({ type: 'error', message: 'Упс, что то пошло не так...', }) } } ) return (

Отправить посылку

Заполните информацию о вашей посылке и маршруте

{/* тип груза и транспорта */}
{ handleChange({ target: { id: 'cargo_type', value: e.target.value[0]?.toString() || '', }, }) }} name="cargo_type" options={cargoOptions} className="mt-1" placeholder="Выберите тип груза" noOptionsMessage="Нет доступных типов груза" />
{ handleChange({ target: { id: 'transport', value: e.target.value[0]?.toString() || '', }, }) }} name="transport" options={transportOptions} className="mt-1" placeholder="Выберите способ перевозки" noOptionsMessage="Нет доступных способов перевозки" />
{/* маршрут */}

Маршрут

{/* даты */}
{/* контактная информация */}

Контактная информация

{/* кнопки действий */}
) } export default SenderPage