backend logic

This commit is contained in:
2025-05-24 14:55:27 +03:00
parent e4fcf0716d
commit b755eda4b5
7 changed files with 160 additions and 31 deletions

View File

@@ -25,7 +25,7 @@ interface RouteFormProps {
description: string
}
const formatDateToHTML = (date: Date) => {
export 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')

View File

@@ -7,13 +7,14 @@ import TextInput from '../ui/TextInput'
import TextAreaInput from '../ui/TextAreaInput'
import PhoneInput from '../ui/PhoneInput'
import useUserStore from '@/app/store/userStore'
import { sendLead } from '@/lib/main/sendLead'
const validationRules = {
name: { required: true },
phone_number: { required: true },
email: { required: true },
price: { required: false },
deliveryTime: { required: false },
moving_price: { required: true },
moving_date: { required: true },
comment: { required: false },
}
@@ -26,21 +27,24 @@ interface LeadPopupProps {
const LeadPopup = ({ id, isOpen, onClose, onSuccess }: LeadPopupProps) => {
const { user } = useUserStore()
const today = new Date().toISOString().split('T')[0]
const initialValues = {
name: user?.name || '',
phone_number: user?.phone_number || '',
email: user?.email || '',
moving_price: '',
moving_date: '',
comment: '',
id: id,
}
const { values, handleChange, handleSubmit, setValues } = useForm(
{
name: user?.name || '',
phone_number: user?.phone_number || '',
email: user?.email || '',
price: '',
deliveryTime: '',
comment: '',
id: id,
},
initialValues,
validationRules,
async values => {
try {
// await sendLead(values)
await sendLead(values)
showToast({
type: 'success',
message: 'Сообщение отправлено!',
@@ -98,22 +102,28 @@ const LeadPopup = ({ id, isOpen, onClose, onSuccess }: LeadPopupProps) => {
/>
<TextInput
name="price"
value={values.price}
name="moving_price"
value={values.moving_price}
handleChange={handleChange}
label="Предлагаемая цена"
placeholder="Укажите стоимость перевозки"
style="register"
/>
<TextInput
name="deliveryTime"
value={values.deliveryTime}
handleChange={handleChange}
label="Срок доставки"
placeholder="Укажите предполагаемый срок доставки"
style="register"
/>
<div>
<label htmlFor="moving_date" className="block text-sm font-medium text-gray-700">
Срок доставки
</label>
<input
type="date"
name="moving_date"
id="moving_date"
value={values.moving_date}
onChange={handleChange}
min={today}
className="mt-1 block w-full rounded-xl border border-gray-300 px-3 py-2 focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none"
/>
</div>
<TextAreaInput
name="comment"
value={values.comment}