mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 23:39:37 +02:00
Add support for end date to adventure
This commit is contained in:
parent
276ea42138
commit
03e0530e90
9 changed files with 66 additions and 5 deletions
|
@ -221,7 +221,14 @@
|
|||
{#if adventure.date && adventure.date !== ''}
|
||||
<div class="inline-flex items-center">
|
||||
<Calendar class="w-5 h-5 mr-1" />
|
||||
<p>{new Date(adventure.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</p>
|
||||
<p>
|
||||
{new Date(adventure.date).toLocaleDateString(undefined, {
|
||||
timeZone: 'UTC'
|
||||
})}{adventure.end_date && adventure.end_date !== ''
|
||||
? ' - ' +
|
||||
new Date(adventure.end_date).toLocaleDateString(undefined, { timeZone: 'UTC' })
|
||||
: ''}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if adventure.activity_types && adventure.activity_types.length > 0}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
name: adventureToEdit?.name || '',
|
||||
type: adventureToEdit?.type || 'visited',
|
||||
date: adventureToEdit?.date || null,
|
||||
end_date: adventureToEdit?.end_date || null,
|
||||
link: adventureToEdit?.link || null,
|
||||
description: adventureToEdit?.description || null,
|
||||
activity_types: adventureToEdit?.activity_types || [],
|
||||
|
@ -286,6 +287,14 @@
|
|||
|
||||
async function handleSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (adventure.date && adventure.end_date) {
|
||||
if (new Date(adventure.date) > new Date(adventure.end_date)) {
|
||||
addToast('error', 'Start date must be before end date');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(adventure);
|
||||
if (adventure.id === '') {
|
||||
let res = await fetch('/api/adventures', {
|
||||
|
@ -374,7 +383,7 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<label for="date">Date</label><br />
|
||||
<label for="date">Date (or start date)</label><br />
|
||||
<input
|
||||
type="date"
|
||||
id="date"
|
||||
|
@ -385,6 +394,18 @@
|
|||
class="input input-bordered w-full"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="end_date">End Date</label><br />
|
||||
<input
|
||||
type="date"
|
||||
id="end_date"
|
||||
name="end_date"
|
||||
min={startDate || ''}
|
||||
max={endDate || ''}
|
||||
bind:value={adventure.end_date}
|
||||
class="input input-bordered w-full"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<!-- link -->
|
||||
<div>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
let newCollection: Collection = {
|
||||
user_id: NaN,
|
||||
id: NaN,
|
||||
id: '',
|
||||
name: '',
|
||||
description: '',
|
||||
adventures: [] as Adventure[],
|
||||
|
@ -41,6 +41,12 @@
|
|||
const form = event.target as HTMLFormElement;
|
||||
const formData = new FormData(form);
|
||||
|
||||
// make sure that start_date is before end_date
|
||||
if (new Date(newCollection.start_date ?? '') > new Date(newCollection.end_date ?? '')) {
|
||||
addToast('error', 'Start date must be before end date');
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await fetch(form.action, {
|
||||
method: form.method,
|
||||
body: formData
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue