Skip to content

Commit 4502fee

Browse files
authored
Merge pull request #407 from vuejs-jp/feature/add-namecard-register
[WIP]Feature/add namecard register
2 parents cd1b5b4 + 2b87374 commit 4502fee

File tree

16 files changed

+434
-57
lines changed

16 files changed

+434
-57
lines changed

app/assets/locale/all.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export default {
106106
contact_form_name_label: 'お名前/Name',
107107
contact_form_name_placeholder: '山田太郎',
108108
contact_form_mail_label: 'メールアドレス/Mail',
109+
/* register page */
110+
register_form_display_name_label: 'お名前/Name 12文字以内',
111+
register_form_avatar_label: 'アバター/Avatar',
112+
register_form_secret_word_label: 'あいことば',
113+
register_form_receipt_id_label: '注文番号',
109114
/* prettier-ignore */
110115
contact_form_text_label: 'お問い合わせ内容/Content',
111116
contact_submit_done: 'メッセージ送信に成功しました。',
@@ -224,6 +229,11 @@ export default {
224229
contact_form_name_label: 'Name',
225230
contact_form_name_placeholder: 'Yamada Taro',
226231
contact_form_mail_label: 'Mail',
232+
/* register page */
233+
register_form_name_label: 'Name 12 characters max.',
234+
register_form_avatar_label: 'Avatar',
235+
register_form_watchword_label: 'Watchword',
236+
register_form_order_number_label: 'Order Number',
227237
/* prettier-ignore */
228238
contact_form_text_label: 'Content',
229239
contact_submit_done: 'Message sent successfully.',

app/atoms/user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function useStore() {
1313
provider: '',
1414
email: '',
1515
created_at: '',
16+
display_name: '',
17+
receipt_id: '',
1618
},
1719
})
1820

app/components/AlertBar.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
<script setup lang="ts">
2+
const props = defineProps({
3+
userId: {
4+
type: String,
5+
required: true,
6+
},
7+
})
8+
</script>
9+
110
<template>
2-
<a href="/register" class="alert-root">
11+
<nuxt-link to="/user-edit" class="alert-root">
312
チケット購入のまたは紐付けが未完了です。プロフィール画面から登録してください。
4-
</a>
13+
</nuxt-link>
514
</template>
615

716
<style lang="ts" scoped>

app/components/forms/InputField.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type _InputFieldProps = Omit<InputHTMLAttributes, 'onInput' | 'onBlur'>
55
interface InputFieldProps extends /* @vue-ignore */ _InputFieldProps {
66
titleLabel: string
77
error: string
8+
value?: string
89
/**
910
* FIXME 削除したい (削除できなさそう)
1011
*/
@@ -15,7 +16,16 @@ interface InputFieldEmit {
1516
(e: 'blur', value: string): void
1617
}
1718
const props = defineProps<InputFieldProps>()
18-
const { id, name, placeholder = '', type, required = false, titleLabel, error = '' } = toRefs(props)
19+
const {
20+
id,
21+
name,
22+
placeholder = '',
23+
type,
24+
required = false,
25+
titleLabel,
26+
error = '',
27+
value,
28+
} = toRefs(props)
1929
const emit = defineEmits<InputFieldEmit>()
2030
function handleInput(e: Event) {
2131
if (!(e.target instanceof HTMLInputElement)) {
@@ -41,6 +51,7 @@ function handleFocusOut(e: Event) {
4151
class="form-input"
4252
:placeholder="placeholder"
4353
:required="required"
54+
:value="value"
4455
@input="handleInput"
4556
@blur="handleFocusOut"
4657
/>

app/components/namecard/NamecardSection.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<script setup lang="ts">
22
import MarkDownText from '~/components/MarkDownText.vue'
33
import CommentTitle from '~/components/CommentTitle.vue'
4+
import IntegrationCard from '~/components/namecard/IntegrationCard.vue'
45
import RoundButton from '~/components/button/RoundButton.vue'
56
import { useNamecard } from '~/composables/useNamecard'
7+
import { useDialog } from '~/composables/useDialog'
68
79
const { canRegister } = useNamecard()
10+
const { handle, isShow } = useDialog()
811
</script>
912

1013
<template>
@@ -30,17 +33,15 @@ const { canRegister } = useNamecard()
3033
-->
3134
<!-- ネームカードを作成 -->
3235
<div class="apply">
33-
<RoundButton
34-
:to="canRegister ? '/register' : '#'"
35-
target="_blank"
36-
rel="noreferrer"
37-
:disabled="!canRegister"
38-
>
36+
<RoundButton type="submit" :disabled="!canRegister" @click="() => handle(true)">
3937
{{ $t('words.create_namecard') }}
4038
</RoundButton>
4139
</div>
4240
</div>
4341
</div>
42+
<div v-if="isShow">
43+
<IntegrationCard @on-close="() => handle(false)" />
44+
</div>
4445
</template>
4546

4647
<style lang="ts" scoped>

app/composables/useAuth.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const initialUser = {
1111
provider: '',
1212
email: '',
1313
created_at: '',
14+
display_name: '',
15+
receipt_id: '',
1416
}
1517

1618
const dummyUser = {
@@ -20,6 +22,8 @@ const dummyUser = {
2022
provider: 'google',
2123
2224
created_at: '2023-06-02T15:12:03.369752Z',
25+
display_name: 'ダミー表示名',
26+
receipt_id: 'dummydummy',
2327
}
2428

2529
let signedUser = reactive<FormUser>({ ...initialUser })
@@ -49,6 +53,8 @@ const useAuth = () => {
4953
signedUser.provider = user?.app_metadata.provider as AuthProvider
5054
signedUser.email = user?.email || ''
5155
signedUser.created_at = user?.created_at || ''
56+
// signedUser.display_name = user?.display_name || ''
57+
// signedUser.receipt_id = user?.receipt_id || ''
5258
store?.setUser(signedUser)
5359
}
5460
})
@@ -69,7 +75,12 @@ const useAuth = () => {
6975
.exhaustive()
7076
})
7177
const signIn = async (provider: AuthProvider) => {
72-
const { error } = await supabase.auth.signInWithOAuth({ provider })
78+
const { error } = await supabase.auth.signInWithOAuth({
79+
provider,
80+
options: {
81+
redirectTo: isProd ? 'https://vuefes.jp/2023/register' : 'http://localhost:3000/register',
82+
},
83+
})
7384
if (error) {
7485
throw new Error(`can not signin with ${provider === 'github' ? 'GitHub' : 'Google'}`)
7586
}

app/composables/useFormError.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export function useFormError() {
22
const nameError = ref('')
33
const emailError = ref('')
44
const detailError = ref('')
5+
const displayNameError = ref('')
6+
const receiptIdError = ref('')
57

68
function validateName(value: string) {
79
if (value === '') {
@@ -30,12 +32,32 @@ export function useFormError() {
3032
detailError.value = ''
3133
}
3234

35+
function validateDisplayName(value: string) {
36+
if (value === '') {
37+
nameError.value = '名前を入力してください'
38+
return
39+
}
40+
nameError.value = ''
41+
}
42+
43+
function validateReceiptId(value: string) {
44+
if (value === '') {
45+
nameError.value = '名前を入力してください'
46+
return
47+
}
48+
nameError.value = ''
49+
}
50+
3351
return {
3452
nameError,
3553
emailError,
3654
detailError,
55+
displayNameError,
56+
receiptIdError,
3757
validateName,
3858
validateEmail,
3959
validateDetail,
60+
validateDisplayName,
61+
validateReceiptId,
4062
}
4163
}

app/composables/useSupabase.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,57 @@ import { useUserStore } from './useUserStore'
44
import { useToast } from './useToast'
55

66
export function useSupabase() {
7+
const config = useRuntimeConfig()
8+
const { supabaseProjectUrl } = config.public
79
const client = useSupabaseClient<Database>()
810
const { signedUser: user } = useUserStore()
911
const { onError, onSuccess } = useToast()
1012

11-
async function addEventUser(displayName: string, secretWord: string, receiptId: string) {
13+
async function addEventUser(displayName: string, avatarUrl: string, receiptId: string) {
1214
const userData = {
1315
...user,
1416
display_name: displayName,
15-
secret_word: secretWord,
17+
avatar_url: avatarUrl,
1618
receipt_id: receiptId,
1719
}
1820

1921
const { error } = await client.from('event_users').insert(userData)
2022
if (error) {
21-
onError('購入できませんでした', 3000)
23+
onError('登録できませんでした', 3000)
2224
return
2325
}
2426

25-
onSuccess('購入しました', 3000)
27+
onSuccess('登録しました', 3000)
28+
}
29+
30+
async function updateEventUser(
31+
displayName: string,
32+
avatarUrl: string,
33+
receiptId: string,
34+
userId: string,
35+
) {
36+
const userData = {
37+
...user,
38+
display_name: displayName,
39+
avatar_url: avatarUrl,
40+
receipt_id: receiptId,
41+
}
42+
43+
const { error } = await client.from('event_users').update(userData).eq('user_id', userId)
44+
if (error) {
45+
onError('編集できませんでした', 3000)
46+
return
47+
}
48+
49+
onSuccess('編集しました', 3000)
50+
}
51+
52+
function getFullAvatarUrl(avatarUrl: string) {
53+
return `${supabaseProjectUrl}/storage/v1/object/public/avatar/${avatarUrl}`
54+
}
55+
56+
async function uploadAvatar(filePath: string, file: File) {
57+
await client.storage.from('avatar').upload(filePath, file)
2658
}
2759

2860
async function updatePMReceipt(receiptIds: { role: Role; receipt_id: string }[]) {
@@ -38,5 +70,5 @@ export function useSupabase() {
3870
onSuccess('購入情報を取り込みました', 3000)
3971
}
4072

41-
return { addEventUser, updatePMReceipt }
73+
return { addEventUser, updateEventUser, getFullAvatarUrl, uploadAvatar, updatePMReceipt }
4274
}

app/container/NavPageSectionContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const { canRegister } = useNamecard()
1717

1818
<template>
1919
<div v-if="canRegister && hasAuth && !eventUser?.activated_at">
20-
<AlertBar />
20+
<AlertBar :user-id="signedUser.user_id" />
2121
</div>
2222
<NavPageSection :has-alert="canRegister && hasAuth && !eventUser?.activated_at">
2323
<template #avatar>

0 commit comments

Comments
 (0)