diff --git a/src/api/invitations.ts b/src/api/invitations.ts index d325ad8..a899210 100644 --- a/src/api/invitations.ts +++ b/src/api/invitations.ts @@ -14,21 +14,13 @@ export async function acceptInvitation(token: string): Promise { return { id: h.id, name: h.name, slug: h.slug } } -export async function sendInvitation(householdSlug: string, email: string): Promise { - const res = await api.POST('/api/v1/households/{householdSlug}/invitations', { - params: { path: { householdSlug } }, - body: { email }, - }) - if (!res.response.ok) throw new Error(`${res.response.status} ${res.response.statusText || 'HTTP error'}`) -} +export async function createInviteLink(householdSlug: string): Promise { + const { data, error, response } = await api.POST('/api/v1/households/{householdSlug}/invitations', { params: { path: { householdSlug } } }) -export async function createInviteLink(householdSlug: string, email: string): Promise { - const res = await api.POST('/api/v1/households/{householdSlug}/invitations', { - params: { path: { householdSlug } }, - body: { email }, - }) - if (!res.response.ok) throw new Error(`${res.response.status} ${res.response.statusText || 'HTTP error'}`) - const inviteLink = res.data?.invite_link + if (!response.ok) { + throw new Error(`${response.status} ${response.statusText || 'HTTP error'}${error ? `: ${String(error)}` : ''}`) + } + const inviteLink = data?.invite_link if (typeof inviteLink !== 'string') throw new Error('Invalid response: missing invite_link') return inviteLink -} +} \ No newline at end of file diff --git a/src/api/types.ts b/src/api/types.ts index 9593c83..3622ec4 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -462,11 +462,6 @@ export interface components { /** Name */ name: string; }; - /** CreateInvitationBody */ - CreateInvitationBody: { - /** Email */ - email: string; - }; /** CurrentShoppingList */ CurrentShoppingList: { /** Outstandingitems */ @@ -1341,11 +1336,7 @@ export interface operations { }; cookie?: never; }; - requestBody: { - content: { - "application/json": components["schemas"]["CreateInvitationBody"]; - }; - }; + requestBody?: never; responses: { /** @description Successful Response */ 200: { diff --git a/src/views/HouseholdSettings.vue b/src/views/HouseholdSettings.vue index e5f7c97..a19f95c 100644 --- a/src/views/HouseholdSettings.vue +++ b/src/views/HouseholdSettings.vue @@ -3,29 +3,14 @@

Household Members

Invite a member

-
- - - - -
+

Share an invite link with the person you want to add.

+

import { ref, onMounted, computed } from 'vue' -import { sendInvitation, createInviteLink } from '@/api/invitations' +import { createInviteLink } from '@/api/invitations' import { listMembers, type Member } from '@/api/households' import { useRoute } from 'vue-router' import { useAlert } from '@/composables/useAlert' -const email = ref('') const submitting = ref(false) const message = ref('') const error = ref('') @@ -84,23 +68,6 @@ onMounted(async () => { } }) -async function onInvite() { - message.value = '' - error.value = '' - submitting.value = true - try { - const slug = householdSlug.value - if (!slug) throw new Error('No household selected') - await sendInvitation(slug, email.value.trim()) - message.value = 'Invitation sent.' - email.value = '' - } catch (e) { - error.value = e instanceof Error ? e.message : 'Failed to send invitation' - } finally { - submitting.value = false - } -} - async function onCopyInviteLink() { message.value = '' error.value = '' @@ -108,15 +75,11 @@ async function onCopyInviteLink() { try { const slug = householdSlug.value if (!slug) throw new Error('No household selected') - const emailValue = email.value.trim() - if (!emailValue) throw new Error('Please enter an email address') - - const inviteLink = await createInviteLink(slug, emailValue) + const inviteLink = await createInviteLink(slug) await navigator.clipboard.writeText(inviteLink) showAlert({ type: 'success', heading: 'Success', message: 'Invite link copied to clipboard!' }) scheduleAutoDismiss(3000) - email.value = '' } catch (e) { error.value = e instanceof Error ? e.message : 'Failed to copy invite link' } finally { diff --git a/src/views/Welcome.vue b/src/views/Welcome.vue index a46975c..dfb28c6 100644 --- a/src/views/Welcome.vue +++ b/src/views/Welcome.vue @@ -17,7 +17,7 @@

Join an existing household

-

To join a household, ask an existing member to send an invitation to your email address.

+

To join a household, ask an existing member to share an invitation link with you.