2024-07-27 19:22:01 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
|
|
|
import Launch from '~icons/mdi/launch';
|
|
|
|
import TrashCanOutline from '~icons/mdi/trash-can-outline';
|
|
|
|
|
|
|
|
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
|
|
|
|
|
|
|
import { goto } from '$app/navigation';
|
2024-07-29 19:19:24 -04:00
|
|
|
import type { Collection, Transportation, User } from '$lib/types';
|
2024-07-27 19:22:01 -04:00
|
|
|
import { addToast } from '$lib/toasts';
|
|
|
|
|
|
|
|
import Plus from '~icons/mdi/plus';
|
2024-08-19 16:32:08 -04:00
|
|
|
import ArrowDownThick from '~icons/mdi/arrow-down-thick';
|
2024-07-27 19:22:01 -04:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-07-27 21:18:15 -04:00
|
|
|
export let transportation: Transportation;
|
2024-07-29 19:19:24 -04:00
|
|
|
export let user: User | null = null;
|
2024-07-27 19:22:01 -04:00
|
|
|
|
2024-07-27 21:18:15 -04:00
|
|
|
function editTransportation() {
|
|
|
|
dispatch('edit', transportation);
|
2024-07-27 19:22:01 -04:00
|
|
|
}
|
|
|
|
|
2024-07-27 21:18:15 -04:00
|
|
|
async function deleteTransportation() {
|
|
|
|
let res = await fetch(`/api/transportations/${transportation.id}`, {
|
|
|
|
method: 'DELETE',
|
2024-07-27 19:22:01 -04:00
|
|
|
headers: {
|
2024-07-27 21:18:15 -04:00
|
|
|
'Content-Type': 'application/json'
|
2024-07-27 19:22:01 -04:00
|
|
|
}
|
|
|
|
});
|
2024-07-27 21:18:15 -04:00
|
|
|
if (!res.ok) {
|
|
|
|
console.log('Error deleting transportation');
|
2024-07-27 19:22:01 -04:00
|
|
|
} else {
|
2024-07-27 21:18:15 -04:00
|
|
|
console.log('Collection deleted');
|
|
|
|
addToast('info', 'Transportation deleted successfully!');
|
|
|
|
dispatch('delete', transportation.id);
|
2024-07-27 19:22:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div
|
2024-08-19 16:32:08 -04:00
|
|
|
class="card w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-md xl:max-w-md bg-primary-content shadow-xl text-base-content"
|
2024-07-27 19:22:01 -04:00
|
|
|
>
|
|
|
|
<div class="card-body">
|
2024-07-27 21:18:15 -04:00
|
|
|
<h2 class="card-title overflow-ellipsis">{transportation.name}</h2>
|
|
|
|
<div class="badge badge-secondary">{transportation.type}</div>
|
2024-08-19 16:32:08 -04:00
|
|
|
<div>
|
|
|
|
{#if transportation.from_location}
|
|
|
|
<p class="break-words text-wrap">{transportation.from_location}</p>
|
|
|
|
{/if}
|
|
|
|
{#if transportation.to_location}
|
|
|
|
<ArrowDownThick class="w-6 h-6" />
|
|
|
|
<p class="break-words text-wrap">{transportation.to_location}</p>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{#if transportation.date}
|
|
|
|
<p>{new Date(transportation.date).toLocaleString(undefined, { timeZone: 'UTC' })}</p>
|
|
|
|
{/if}
|
|
|
|
{#if transportation.end_date}
|
|
|
|
<ArrowDownThick class="w-6 h-6" />
|
|
|
|
<p>{new Date(transportation.end_date).toLocaleString(undefined, { timeZone: 'UTC' })}</p>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
|
2024-07-31 11:01:41 -04:00
|
|
|
{#if user?.pk === transportation.user_id}
|
2024-07-29 19:19:24 -04:00
|
|
|
<div class="card-actions justify-end">
|
|
|
|
<button on:click={deleteTransportation} class="btn btn-secondary"
|
|
|
|
><TrashCanOutline class="w-5 h-5 mr-1" /></button
|
|
|
|
>
|
|
|
|
<button class="btn btn-primary" on:click={editTransportation}>
|
|
|
|
<FileDocumentEdit class="w-6 h-6" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2024-07-27 19:22:01 -04:00
|
|
|
</div>
|
|
|
|
</div>
|