@frigear-nu/payments 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/payments",
3
3
  "configKey": "payments",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -21,6 +21,8 @@ const module$1 = defineNuxtModule({
21
21
  "@frigear-nu/users": { version: ">=0.0.1" },
22
22
  "@frigear-nu/stripe": { version: ">=0.0.1" },
23
23
  "@frigear-nu/mcp": { version: ">=0.0.1" },
24
+ // `usePayments` loads through `useCachedFetch`; the widgets and the admin tab use its components and helpers.
25
+ "@frigear-nu/ui": { version: ">=0.0.1" },
24
26
  "@frigear-nu/widget": { version: ">=0.0.0", optional: true },
25
27
  // The admin user tab and card are built from its components, so they are only added with it.
26
28
  "@frigear-nu/admin": { version: ">=0.0.0", optional: true }
@@ -1,7 +1,5 @@
1
- /** The signed-in user's payments, plus a helper to resume an unpaid one. */
2
- export declare function usePayments(): {
3
- payments: any;
4
- refresh: any;
5
- status: any;
6
- resume: (paymentId: string) => Promise<void>;
7
- };
1
+ /**
2
+ * The signed-in user's payments, plus a helper to resume an unpaid one. Awaitable: `await usePayments()` in a page
3
+ * renders them on the server. `payments` is `[]` until loaded and after an error: check `loading` and `error` first.
4
+ */
5
+ export declare function usePayments(): any;
@@ -1,14 +1,20 @@
1
1
  export function usePayments() {
2
2
  const { loggedIn } = useUserSession();
3
- const { data, refresh, status } = useFetch("/api/payments", {
3
+ const fetched = useCachedFetch("/api/payments", {
4
4
  key: "payments:mine",
5
- immediate: loggedIn.value,
6
- watch: false,
7
- default: () => []
5
+ ttl: 60 * 1e3,
6
+ watch: false
8
7
  });
8
+ const { status, error, loading, refresh, clear } = fetched;
9
+ watch(loggedIn, (value) => {
10
+ if (value) refresh();
11
+ else clear();
12
+ });
13
+ const payments = computed(() => fetched.data.value ?? []);
9
14
  async function resume(paymentId) {
10
15
  const { url } = await $fetch("/api/payments/resume", { method: "POST", body: { paymentId } });
11
16
  await navigateTo(url, { external: true });
12
17
  }
13
- return { payments: data, refresh, status, resume };
18
+ const api = { payments, refresh, status, error, loading, resume };
19
+ return Object.assign(fetched.then(() => api), api);
14
20
  }
@@ -6,10 +6,11 @@ const props = defineProps({
6
6
  const t = useModuleT("payments.admin");
7
7
  const status = useModuleT("payments.status");
8
8
  const format = useFormat();
9
- const { data: payments, status: fetchStatus } = useLazyFetch(
9
+ const { data: payments, status: fetchStatus, error } = useLazyFetch(
10
10
  () => `/api/admin/users/${props.user.id}/payments`,
11
11
  { key: () => `admin-payments-${props.user.id}` }
12
12
  );
13
+ const loading = computed(() => fetchStatus.value === "pending" && !payments.value);
13
14
  const statusLabel = (value) => status(value, value);
14
15
  const columns = computed(() => [
15
16
  { accessorKey: "createdAt", header: t("date", "Date") },
@@ -22,7 +23,10 @@ const columns = computed(() => [
22
23
  </script>
23
24
 
24
25
  <template>
25
- <TableCard>
26
+ <TableCard
27
+ :loading="loading"
28
+ :refreshing="fetchStatus === 'pending' && !loading"
29
+ >
26
30
  <template #header>
27
31
  <h2 class="text-highlighted text-sm font-semibold">
28
32
  {{ t("title", "Payments") }}
@@ -31,7 +35,6 @@ const columns = computed(() => [
31
35
  <UTable
32
36
  :data="payments ?? []"
33
37
  :columns="columns"
34
- :loading="fetchStatus === 'pending'"
35
38
  :ui="tableUi({ tr: '' })"
36
39
  >
37
40
  <template #createdAt-cell="{ row }">
@@ -58,6 +61,14 @@ const columns = computed(() => [
58
61
  </template>
59
62
  <template #empty>
60
63
  <UEmpty
64
+ v-if="error"
65
+ icon="i-lucide-circle-alert"
66
+ variant="naked"
67
+ :title="t('loadFailed', 'The payments could not be loaded')"
68
+ :description="errorMessage(error, '')"
69
+ />
70
+ <UEmpty
71
+ v-else
61
72
  icon="i-lucide-credit-card"
62
73
  variant="naked"
63
74
  :title="t('empty', 'No payments yet')"
@@ -14,6 +14,7 @@
14
14
  "title": "Betalinger",
15
15
  "lastPayment": "Seneste betaling",
16
16
  "empty": "Ingen betalinger endnu",
17
+ "loadFailed": "Betalingerne kunne ikke hentes",
17
18
  "date": "Dato",
18
19
  "description": "Beskrivelse",
19
20
  "amount": "Beløb",
@@ -14,6 +14,7 @@
14
14
  "title": "Payments",
15
15
  "lastPayment": "Last payment",
16
16
  "empty": "No payments yet",
17
+ "loadFailed": "The payments could not be loaded",
17
18
  "date": "Date",
18
19
  "description": "Description",
19
20
  "amount": "Amount",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/payments",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "One-time payments (Stripe Checkout, refunds and payment lifecycle hooks) for the frigear ecosystem, built on @frigear-nu/stripe.",
5
5
  "homepage": "https://docs.frigear.dev/modules/payments",
6
6
  "repository": {
@@ -30,12 +30,12 @@
30
30
  "playground"
31
31
  ],
32
32
  "dependencies": {
33
- "@frigear-nu/auth": "0.1.2",
34
- "@frigear-nu/mcp": "0.1.1",
35
- "@frigear-nu/module-kit": "1.1.1",
36
- "@frigear-nu/stripe": "0.1.1",
37
- "@frigear-nu/ui": "0.1.1",
38
- "@frigear-nu/users": "1.1.2",
33
+ "@frigear-nu/auth": "0.1.3",
34
+ "@frigear-nu/mcp": "0.1.2",
35
+ "@frigear-nu/module-kit": "1.1.2",
36
+ "@frigear-nu/stripe": "0.1.2",
37
+ "@frigear-nu/ui": "0.1.2",
38
+ "@frigear-nu/users": "1.1.3",
39
39
  "@libsql/client": "^0.18.0",
40
40
  "@nuxt/kit": "^4.6.1",
41
41
  "drizzle-kit": "^0.31.11",
@@ -46,8 +46,8 @@
46
46
  "zod": "^4.6.5"
47
47
  },
48
48
  "peerDependencies": {
49
- "@frigear-nu/widget": "0.1.1",
50
- "@nuxt/ui": "^4.11.2",
49
+ "@frigear-nu/widget": "0.1.2",
50
+ "@nuxt/ui": "^4.12.0",
51
51
  "@nuxthub/core": "^0.10.8"
52
52
  },
53
53
  "peerDependenciesMeta": {
@@ -59,13 +59,13 @@
59
59
  }
60
60
  },
61
61
  "devDependencies": {
62
- "@frigear-nu/widget": "0.1.1",
62
+ "@frigear-nu/widget": "0.1.2",
63
63
  "@nuxt/devtools": "^3.4.2",
64
64
  "@nuxt/eslint-config": "^1.17.0",
65
65
  "@nuxt/module-builder": "^1.0.3",
66
66
  "@nuxt/schema": "^4.6.1",
67
67
  "@nuxt/test-utils": "^4.3.2",
68
- "@nuxt/ui": "^4.11.2",
68
+ "@nuxt/ui": "^4.12.0",
69
69
  "@nuxthub/core": "^0.10.8",
70
70
  "@types/node": "^26.6.5",
71
71
  "changelogen": "^0.6.2",