Full UI 180 & Overall improvements
This commit is contained in:
34
src/utils/trips.js
Normal file
34
src/utils/trips.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { parseYMD } from './date';
|
||||
|
||||
export function validateTripDraft({ name = '', startDate = '', endDate = '' }) {
|
||||
if (!`${name || ''}`.trim()) {
|
||||
return {
|
||||
valid: false,
|
||||
title: 'Missing name',
|
||||
message: 'Trip name is required.',
|
||||
};
|
||||
}
|
||||
|
||||
const start = parseYMD(startDate);
|
||||
const end = parseYMD(endDate);
|
||||
|
||||
if (!start || !end) {
|
||||
return {
|
||||
valid: false,
|
||||
title: 'Invalid dates',
|
||||
message: 'Please select valid trip dates.',
|
||||
};
|
||||
}
|
||||
|
||||
if (start > end) {
|
||||
return {
|
||||
valid: false,
|
||||
title: 'Invalid dates',
|
||||
message: 'Start date cannot be after end date.',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user