Skip to content

Commit

Permalink
Fix date and time issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Apr 14, 2024
1 parent 674ce2b commit d96d180
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 46 deletions.
27 changes: 12 additions & 15 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@mui/x-data-grid": "^7.1.1",
"@mui/x-date-pickers": "^7.1.1",
"@mui/x-date-pickers": "^7.2.0",
"@types/draftjs-to-html": "^0.8.4",
"@types/html-to-draftjs": "^1.4.3",
"@types/node": "^20.12.7",
"@types/react": "^18.2.77",
"@types/react": "^18.2.78",
"@types/react-dom": "^18.2.25",
"@types/react-draft-wysiwyg": "^1.13.8",
"@types/validator": "^13.11.9",
"axios": "^1.6.8",
"date-fns": "^2.25.0",
"date-fns": "^2.29.3",
"draft-js": "^0.11.7",
"draftjs-to-html": "^0.9.1",
"html-to-draftjs": "^1.5.0",
Expand Down
3 changes: 3 additions & 0 deletions backend/src/components/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface DatePickerProps {
value?: Date
label?: string
minDate?: Date
maxDate?: Date
required?: boolean
language?: string
variant?: TextFieldVariants
Expand All @@ -19,6 +20,7 @@ const DatePicker = ({
value: dateValue,
label,
minDate,
maxDate,
required,
language,
variant,
Expand Down Expand Up @@ -48,6 +50,7 @@ const DatePicker = ({
}
}}
minDate={minDate}
maxDate={maxDate}
slotProps={{
textField: {
variant: variant || 'standard',
Expand Down
4 changes: 4 additions & 0 deletions backend/src/components/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface DateTimePickerProps {
value?: Date
label?: string
minDate?: Date
maxDate?: Date
required?: boolean
language?: string
variant?: TextFieldVariants
Expand All @@ -19,6 +20,7 @@ const DateTimePicker = ({
value: dateTimeValue,
label,
minDate,
maxDate,
required,
variant,
language,
Expand All @@ -44,6 +46,8 @@ const DateTimePicker = ({
}
}}
minDate={minDate}
maxDate={maxDate}
timeSteps={{ hours: 1, minutes: 5 }}
slotProps={{
textField: {
variant: variant || 'standard',
Expand Down
16 changes: 13 additions & 3 deletions backend/src/pages/CreateBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const CreateBooking = () => {
const [location, setLocation] = useState('')
const [from, setFrom] = useState<Date>()
const [to, setTo] = useState<Date>()
const [minDate, setMinDate] = useState<Date>()
const [maxDate, setMaxDate] = useState<Date>()
const [status, setStatus] = useState<movininTypes.BookingStatus>()
const [cancellation, setCancellation] = useState(false)
const [minDate, setMinDate] = useState<Date>()
const [loading, setLoading] = useState(false)

const handleAgencyChange = (values: movininTypes.Option[]) => {
Expand Down Expand Up @@ -183,6 +184,7 @@ const CreateBooking = () => {
<DatePicker
label={commonStrings.FROM}
value={from}
maxDate={maxDate}
required
onChange={(date) => {
if (date) {
Expand All @@ -209,8 +211,16 @@ const CreateBooking = () => {
value={to}
minDate={minDate}
required
onChange={(_to) => {
setTo(_to || undefined)
onChange={(date) => {
if (date) {
const _maxDate = new Date(date)
_maxDate.setDate(_maxDate.getDate() - 1)
setMaxDate(_maxDate)
setTo(date)
} else {
setMaxDate(undefined)
setTo(undefined)
}
}}
language={UserService.getLanguage()}
/>
Expand Down
22 changes: 17 additions & 5 deletions backend/src/pages/UpdateBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ const UpdateBooking = () => {
const [location, setLocation] = useState<movininTypes.Option>()
const [from, setFrom] = useState<Date>()
const [to, setTo] = useState<Date>()
const [minDate, setMinDate] = useState<Date>()
const [maxDate, setMaxDate] = useState<Date>()
const [status, setStatus] = useState<movininTypes.BookingStatus>()
const [cancellation, setCancellation] = useState(false)
const [openDeleteDialog, setOpenDeleteDialog] = useState(false)
const [minDate, setMinDate] = useState<Date>()

const handleAgencyChange = (values: movininTypes.Option[]) => {
setAgency(values.length > 0 ? values[0] : undefined)
Expand Down Expand Up @@ -253,6 +254,9 @@ const UpdateBooking = () => {
_minDate.setDate(_minDate.getDate() + 1)
setMinDate(_minDate)
setTo(new Date(_booking.to))
const _maxDate = new Date(_booking.to)
_maxDate.setDate(_maxDate.getDate() - 1)
setMaxDate(_maxDate)
setStatus(_booking.status)
setCancellation(_booking.cancellation || false)
} else {
Expand Down Expand Up @@ -327,6 +331,7 @@ const UpdateBooking = () => {
<DatePicker
label={commonStrings.FROM}
value={from}
maxDate={maxDate}
required
onChange={(date) => {
if (date) {
Expand Down Expand Up @@ -366,22 +371,29 @@ const UpdateBooking = () => {
value={to}
minDate={minDate}
required
onChange={(_to) => {
if (_to) {
booking.to = _to
onChange={(date) => {
if (date) {
booking.to = date

helper.price(
booking,
booking.property as movininTypes.Property,
(_price) => {
setBooking(booking)
setPrice(_price)
setTo(_to)
setTo(date)

const _maxDate = new Date(date)
_maxDate.setDate(_maxDate.getDate() - 1)
setMaxDate(_maxDate)
},
(err) => {
toastErr(err)
},
)
} else {
setTo(undefined)
setMaxDate(undefined)
}
}}
language={UserService.getLanguage()}
Expand Down
27 changes: 12 additions & 15 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"@mui/icons-material": "^5.15.15",
"@mui/material": "^5.15.15",
"@mui/x-data-grid": "^7.1.1",
"@mui/x-date-pickers": "^7.1.1",
"@mui/x-date-pickers": "^7.2.0",
"@types/node": "^20.12.7",
"@types/react": "^18.2.77",
"@types/react": "^18.2.78",
"@types/react-dom": "^18.2.25",
"@types/react-google-recaptcha": "^2.1.9",
"@types/validator": "^13.11.9",
"axios": "^1.6.8",
"date-fns": "^2.25.0",
"date-fns": "^2.29.3",
"react": "^18.2.0",
"react-app-alias-ex": "^2.1.0",
"react-dom": "^18.2.0",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface DatePickerProps {
value?: Date
label?: string
minDate?: Date
maxDate?: Date
required?: boolean
language?: string
variant?: TextFieldVariants
Expand All @@ -20,6 +21,7 @@ const DatePicker = ({
value: dateValue,
label,
minDate,
maxDate,
required,
language,
variant,
Expand Down Expand Up @@ -51,6 +53,7 @@ const DatePicker = ({
}
}}
minDate={minDate}
maxDate={maxDate}
slotProps={{
textField: {
variant: variant || 'standard',
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface DateTimePickerProps {
value?: Date
label?: string
minDate?: Date
maxDate?: Date
required?: boolean
language?: string
variant?: TextFieldVariants
Expand All @@ -20,6 +21,7 @@ const DateTimePicker = ({
value: dateTimeValue,
label,
minDate,
maxDate,
required,
variant,
language,
Expand Down Expand Up @@ -47,6 +49,8 @@ const DateTimePicker = ({
}
}}
minDate={minDate}
maxDate={maxDate}
timeSteps={{ hours: 1, minutes: 5 }}
slotProps={{
textField: {
variant: variant || 'standard',
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Home = () => {
const [from, setFrom] = useState<Date>()
const [to, setTo] = useState<Date>()
const [minDate, setMinDate] = useState<Date>(_minDate)
const [maxDate, setMaxDate] = useState<Date>()

useEffect(() => {
if (from) {
Expand Down Expand Up @@ -79,6 +80,7 @@ const Home = () => {
label={commonStrings.FROM}
value={from}
minDate={new Date()}
maxDate={maxDate}
variant="outlined"
required
onChange={(date) => {
Expand Down Expand Up @@ -107,7 +109,15 @@ const Home = () => {
variant="outlined"
required
onChange={(date) => {
setTo(date || undefined)
if (date) {
setTo(date)
const _maxDate = new Date(date)
_maxDate.setDate(_maxDate.getDate() - 1)
setMaxDate(_maxDate)
} else {
setTo(undefined)
setMaxDate(undefined)
}
}}
language={UserService.getLanguage()}
/>
Expand Down
Loading

0 comments on commit d96d180

Please sign in to comment.