165 lines
6.6 KiB
Vue
165 lines
6.6 KiB
Vue
<script setup lang="ts">
|
|
import type { PotView } from '~/types';
|
|
|
|
const { t } = useI18n();
|
|
const route = useRoute();
|
|
const slug = route.params.slug as string;
|
|
const { name, setName } = useIdentity();
|
|
|
|
const { data, refresh, error } = await useFetch<PotView>(`/api/pots/${slug}`);
|
|
const { recordVisit } = useVisitedPots();
|
|
|
|
const me = computed(() =>
|
|
data.value?.participants.find(
|
|
(p) => p.name.toLowerCase() === name.value?.toLowerCase(),
|
|
),
|
|
);
|
|
|
|
watch(
|
|
data,
|
|
(pot) => {
|
|
if (!pot) return;
|
|
recordVisit({
|
|
slug: pot.pot.slug,
|
|
name: pot.pot.name,
|
|
currency: pot.pot.currency,
|
|
});
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
const linkCopied = ref(false);
|
|
|
|
// Settings/setup keep their own dedicated layout; only the People &
|
|
// balances / Expenses tabs share this header.
|
|
const isPotTab = computed(
|
|
() => route.path === `/p/${slug}` || route.path === `/p/${slug}/expenses`,
|
|
);
|
|
|
|
async function addMyself() {
|
|
if (!name.value) return;
|
|
await $fetch(`/api/pots/${slug}/participants`, {
|
|
method: 'POST',
|
|
body: { name: name.value },
|
|
});
|
|
await refresh();
|
|
}
|
|
|
|
async function copyLink() {
|
|
await navigator.clipboard.writeText(window.location.href);
|
|
linkCopied.value = true;
|
|
setTimeout(() => (linkCopied.value = false), 2000);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="error" class="space-y-3 text-center">
|
|
<p class="text-rose-600 dark:text-rose-400">{{ t('pot.notFound') }}</p>
|
|
<NuxtLink to="/" class="font-medium text-orange-600 dark:text-orange-400">
|
|
{{ t('pot.goHome') }}
|
|
</NuxtLink>
|
|
</div>
|
|
|
|
<NameForm
|
|
v-else-if="!name && isPotTab"
|
|
:title="t('pot.whatIsYourName')"
|
|
@submit="setName"
|
|
/>
|
|
|
|
<div v-else-if="data" class="space-y-6">
|
|
<template v-if="isPotTab">
|
|
<NuxtLink
|
|
to="/"
|
|
class="inline-flex items-center gap-1 text-sm font-medium text-stone-500 transition-colors hover:text-orange-600 dark:text-stone-400 dark:hover:text-orange-400"
|
|
>
|
|
<svg class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
|
|
<path
|
|
fill-rule="evenodd"
|
|
d="M17 10a.75.75 0 0 1-.75.75H5.612l4.158 3.96a.75.75 0 1 1-1.04 1.08l-5.5-5.25a.75.75 0 0 1 0-1.08l5.5-5.25a.75.75 0 1 1 1.04 1.08L5.612 9.25H16.25A.75.75 0 0 1 17 10Z"
|
|
clip-rule="evenodd"
|
|
/>
|
|
</svg>
|
|
{{ t('pot.allPots') }}
|
|
</NuxtLink>
|
|
|
|
<div class="flex items-start justify-between gap-2">
|
|
<div>
|
|
<h1 class="text-xl font-bold text-stone-900 dark:text-stone-100">
|
|
{{ data.pot.name }}
|
|
</h1>
|
|
<p class="text-sm text-stone-500 dark:text-stone-400">
|
|
{{ data.pot.currency }}
|
|
</p>
|
|
</div>
|
|
<div class="flex shrink-0 gap-2">
|
|
<button
|
|
type="button"
|
|
class="rounded-xl border border-stone-300 px-3 py-1.5 text-sm font-medium text-stone-700 transition-colors hover:border-orange-300 hover:text-orange-600 dark:border-stone-700 dark:text-stone-300 dark:hover:border-orange-700 dark:hover:text-orange-400"
|
|
@click="copyLink"
|
|
>
|
|
{{ linkCopied ? t('pot.linkCopied') : t('pot.copyLink') }}
|
|
</button>
|
|
<NuxtLink
|
|
:to="`/p/${slug}/settings`"
|
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-stone-300 text-stone-600 transition-colors hover:border-orange-300 hover:text-orange-600 dark:border-stone-700 dark:text-stone-300 dark:hover:border-orange-700 dark:hover:text-orange-400"
|
|
:aria-label="t('pot.settingsLabel')"
|
|
>
|
|
<svg class="h-4.5 w-4.5" viewBox="0 0 20 20" fill="currentColor">
|
|
<path
|
|
fill-rule="evenodd"
|
|
d="M7.83922 1.80388C7.93271 1.33646 8.34312 1 8.81981 1H11.1802C11.6569 1 12.0673 1.33646 12.1608 1.80388L12.4913 3.45629C13.1956 3.72458 13.8454 4.10332 14.4196 4.57133L16.0179 4.03065C16.4694 3.8779 16.966 4.06509 17.2043 4.47791L18.3845 6.52207C18.6229 6.93489 18.5367 7.45855 18.1786 7.77322L16.9119 8.88645C16.9699 9.24909 17 9.62103 17 10C17 10.379 16.9699 10.7509 16.9119 11.1135L18.1786 12.2268C18.5367 12.5414 18.6229 13.0651 18.3845 13.4779L17.2043 15.5221C16.966 15.9349 16.4694 16.1221 16.0179 15.9693L14.4196 15.4287C13.8454 15.8967 13.1956 16.2754 12.4913 16.5437L12.1608 18.1961C12.0673 18.6635 11.6569 19 11.1802 19H8.81981C8.34312 19 7.93271 18.6635 7.83922 18.1961L7.50874 16.5437C6.80443 16.2754 6.1546 15.8967 5.58043 15.4287L3.98214 15.9694C3.5306 16.1221 3.03401 15.9349 2.79567 15.5221L1.61547 13.4779C1.37713 13.0651 1.4633 12.5415 1.82136 12.2268L3.08808 11.1135C3.03012 10.7509 3 10.379 3 10C3 9.62103 3.03012 9.2491 3.08808 8.88647L1.82136 7.77324C1.46331 7.45857 1.37713 6.93491 1.61547 6.52209L2.79567 4.47793C3.03401 4.06511 3.5306 3.87791 3.98214 4.03066L5.58042 4.57134C6.15459 4.10332 6.80442 3.72459 7.50874 3.45629L7.83922 1.80388ZM10 13C11.6569 13 13 11.6569 13 10C13 8.34315 11.6569 7 10 7C8.34315 7 7 8.34315 7 10C7 11.6569 8.34315 13 10 13Z"
|
|
clip-rule="evenodd"
|
|
/>
|
|
</svg>
|
|
</NuxtLink>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="!me"
|
|
class="rounded-2xl border border-orange-200 bg-orange-50 p-4 text-sm dark:border-orange-900 dark:bg-orange-950/40"
|
|
>
|
|
<p class="mb-2 text-stone-700 dark:text-stone-300">
|
|
{{ t('pot.notInPot') }}
|
|
</p>
|
|
<button
|
|
type="button"
|
|
class="rounded-xl bg-orange-500 px-3 py-1.5 font-medium text-white shadow-sm transition-colors hover:bg-orange-600"
|
|
@click="addMyself"
|
|
>
|
|
{{ t('pot.addMyself', { name }) }}
|
|
</button>
|
|
</div>
|
|
|
|
<div
|
|
class="grid grid-cols-2 gap-1 rounded-xl bg-stone-100 p-1 dark:bg-stone-900"
|
|
>
|
|
<NuxtLink
|
|
:to="`/p/${slug}`"
|
|
class="rounded-lg py-2 text-center text-sm font-medium transition-colors"
|
|
:class="
|
|
route.path === `/p/${slug}`
|
|
? 'bg-white text-stone-900 shadow-sm dark:bg-stone-800 dark:text-stone-100'
|
|
: 'text-stone-500 hover:text-stone-700 dark:text-stone-400 dark:hover:text-stone-200'
|
|
"
|
|
>
|
|
{{ t('pot.tabPeople') }}
|
|
</NuxtLink>
|
|
<NuxtLink
|
|
:to="`/p/${slug}/expenses`"
|
|
class="rounded-lg py-2 text-center text-sm font-medium transition-colors"
|
|
:class="
|
|
route.path === `/p/${slug}/expenses`
|
|
? 'bg-white text-stone-900 shadow-sm dark:bg-stone-800 dark:text-stone-100'
|
|
: 'text-stone-500 hover:text-stone-700 dark:text-stone-400 dark:hover:text-stone-200'
|
|
"
|
|
>
|
|
{{ t('pot.tabExpenses') }}
|
|
</NuxtLink>
|
|
</div>
|
|
</template>
|
|
|
|
<NuxtPage />
|
|
</div>
|
|
</template>
|