import { mdiCalendarCheck } from '@mdi/js' import Head from 'next/head' import React, { ReactElement } from 'react' import { Field, Form, Formik } from 'formik' import { useRouter } from 'next/router' import BaseButton from '../../components/BaseButton' import BaseButtons from '../../components/BaseButtons' import BaseDivider from '../../components/BaseDivider' import CardBox from '../../components/CardBox' import FormField from '../../components/FormField' import SectionMain from '../../components/SectionMain' import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton' import { SelectField } from '../../components/SelectField' import { SwitchField } from '../../components/SwitchField' import { getPageTitle } from '../../config' import { getRoleLaneFromUser } from '../../helpers/roleLanes' import LayoutAuthenticated from '../../layouts/Authenticated' import { create } from '../../stores/reservations/reservationsSlice' import { useAppDispatch, useAppSelector } from '../../stores/hooks' const initialValues = { tenant: null, organization: null, booking_request: null, reservation_code: '', status: 'quoted', property: null, unit: null, unit_type: null, check_in_at: '', check_out_at: '', actual_check_in_at: '', actual_check_out_at: '', early_check_in: false, late_check_out: false, guest_count: '', nightly_rate: '', monthly_rate: '', currency: 'USD', internal_notes: '', external_notes: '', } const ReservationsNew = () => { const router = useRouter() const dispatch = useAppDispatch() const { currentUser } = useAppSelector((state) => state.auth) const roleLane = getRoleLaneFromUser(currentUser) const canManagePlatformFields = roleLane === 'super_admin' const canManageFinancialFields = canManagePlatformFields || roleLane === 'admin' const canManageOperations = roleLane !== 'customer' const pageTitle = roleLane === 'customer' ? 'My Stay' : 'Create Stay' const introCopy = canManagePlatformFields ? 'Create a stay record with full routing control, internal reference fields, and operational details.' : canManageFinancialFields ? 'Create the stay record that will execute an approved request, assign housing, and prepare arrival details.' : 'Create the stay record for operations. Platform routing and internal references stay managed in the background.' const handleSubmit = async (values) => { const payload = { ...values } if (!canManagePlatformFields) { delete payload.tenant delete payload.organization delete payload.reservation_code } if (!canManageFinancialFields) { delete payload.nightly_rate delete payload.monthly_rate delete payload.internal_notes } await dispatch(create(payload)) await router.push('/reservations/reservations-list') } return ( <> {getPageTitle(pageTitle)} {''}
{introCopy}
{canManagePlatformFields && ( <> )} {canManageOperations && ( <> )} {canManageFinancialFields && ( <> )}
{canManageFinancialFields && (
)}
router.push('/reservations/reservations-list')} />
) } ReservationsNew.getLayout = function getLayout(page: ReactElement) { return {page} } export default ReservationsNew