2024-07-27 19:22:01 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import TrashCanOutline from '~icons/mdi/trash-can-outline';
|
|
|
|
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
2024-09-09 13:31:00 -04:00
|
|
|
import type { Collection, Transportation, User } from '$lib/types';
|
2024-07-27 19:22:01 -04:00
|
|
|
import { addToast } from '$lib/toasts';
|
|
|
|
|
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-09-09 13:31:00 -04:00
|
|
|
export let collection: Collection | 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-09-06 23:35:48 -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-neutral text-neutral-content shadow-xl"
|
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-09-09 13:31:00 -04:00
|
|
|
{#if transportation.user_id == user?.pk || (collection && user && collection.shared_with.includes(user.uuid))}
|
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>
|