From a9d38fff0957ecf36c0a89cb39507c1de20e3798 Mon Sep 17 00:00:00 2001 From: KannoStanfoot Date: Thu, 18 Jul 2024 01:15:19 +0900 Subject: [PATCH 1/9] feat: update data retrieval method for attendees --- apps/web/app/composables/useAuth.ts | 6 +- apps/web/app/composables/useSupabase.ts | 6 +- apps/web/app/pages/namecard/[id]/index.vue | 66 +++++++++++++++------- apps/web/app/pages/namecard/index.vue | 12 ++-- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/apps/web/app/composables/useAuth.ts b/apps/web/app/composables/useAuth.ts index 89d4e9f8..cd54f17e 100644 --- a/apps/web/app/composables/useAuth.ts +++ b/apps/web/app/composables/useAuth.ts @@ -30,9 +30,5 @@ export function useAuth() { return data.user } - const authUserId = getUser().then(user => { - return user.id - }).catch(()=> null) - - return { signIn, signOut, authUserId } + return { signIn, signOut, getUser } } diff --git a/apps/web/app/composables/useSupabase.ts b/apps/web/app/composables/useSupabase.ts index e78165ea..5c86b2a0 100644 --- a/apps/web/app/composables/useSupabase.ts +++ b/apps/web/app/composables/useSupabase.ts @@ -20,6 +20,10 @@ export function useSupabase() { return await client.from(table).select().eq('role', role) } + async function fetchAttendeeDataByUserId(table: Extract, userId:string) { + return await client.from(table).select().eq('user_id', userId) + } + async function upsertSpeaker(table: Extract, target: FormSpeaker) { const targetData = { ...target } @@ -52,5 +56,5 @@ export function useSupabase() { await client.storage.from(bucket).upload(filePath, file) } - return { fetchData, fetchAttendeeData, upsertSpeaker, upsertSponsor, upsertAttendee, upsertStaff, uploadAvatar } + return { fetchData, fetchAttendeeData, fetchAttendeeDataByUserId, upsertSpeaker, upsertSponsor, upsertAttendee, upsertStaff, uploadAvatar } } diff --git a/apps/web/app/pages/namecard/[id]/index.vue b/apps/web/app/pages/namecard/[id]/index.vue index 17766a24..678a9f72 100644 --- a/apps/web/app/pages/namecard/[id]/index.vue +++ b/apps/web/app/pages/namecard/[id]/index.vue @@ -1,23 +1,45 @@ From a26b44d93609bf3eeb8aa65dea92f1c79730a518 Mon Sep 17 00:00:00 2001 From: KannoStanfoot Date: Fri, 19 Jul 2024 04:47:28 +0900 Subject: [PATCH 3/9] feat: refactor: atendee information retrieval into a composable --- apps/web/app/composables/useNamecard.ts | 49 ++++++++++++++++++++++ apps/web/app/pages/namecard/[id]/index.vue | 47 +++------------------ 2 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 apps/web/app/composables/useNamecard.ts diff --git a/apps/web/app/composables/useNamecard.ts b/apps/web/app/composables/useNamecard.ts new file mode 100644 index 00000000..d755b2ea --- /dev/null +++ b/apps/web/app/composables/useNamecard.ts @@ -0,0 +1,49 @@ +import { computed } from 'vue' +import { useSupabase, useAsyncData, useAuth } from '#imports' +import type { Status } from '~/components/namecard/CreationStatus.vue' +import type { Attendee } from '@vuejs-jp/model' + + +export async function useNamecard() { + const { fetchAttendeeDataByUserId } = useSupabase() + const { getUser } = useAuth() + + const { data: authUserId } = await useAsyncData('authUserId', async () => { + return (await getUser()).id + }) + + const { data: attendeeByUserId } = await useAsyncData('attendeeByUserId', async () => { + return await fetchAttendeeDataByUserId('attendees', authUserId.value ?? '') + }) + + const userData = computed(() => { + return attendeeByUserId.value?.data?.[0] + }) + + const statusKey = computed(() => { + // TODO テーブルのどの箇所を参照して全ステータスを判定する? + if (userData.value?.activated_at) { + return 'inquiry_in_progress' + } else { + return 'not_created' + } + }) + + const attendee = computed(() => { + // TODO time 系は空文字じゃない方が良い。supabase側で設定できるのか、フロント側でnew Date使うのか? + return { + id: userData.value?.id ?? '', + user_id: userData.value?.user_id ?? '', + activated_at: userData.value?.activated_at ?? '', + created_at: userData.value?.created_at ?? '', + updated_at: userData.value?.updated_at ?? '', + display_name: userData.value?.display_name ?? '', + email: userData.value?.email ?? '', + provider: userData.value?.provider ?? '', + avatar_url: userData.value?.avatar_url ?? '', + role: userData.value?.role ?? '', + receipt_id: userData.value?.receipt_id ?? '', + } + }) + return { authUserId, userData, statusKey, attendee } +} \ No newline at end of file diff --git a/apps/web/app/pages/namecard/[id]/index.vue b/apps/web/app/pages/namecard/[id]/index.vue index 678a9f72..c666b0a9 100644 --- a/apps/web/app/pages/namecard/[id]/index.vue +++ b/apps/web/app/pages/namecard/[id]/index.vue @@ -1,57 +1,22 @@