Skip to content

Commit

Permalink
feat: /membership にユーザーの状態選択およびログイン・メールアドレス認証のプロトタイプを実装
Browse files Browse the repository at this point in the history
  • Loading branch information
reiroop committed Jan 1, 2025
1 parent a3c69f5 commit 01feaff
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/composable/parseRouteQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { LocationQueryValue } from 'vue-router'

export const parseRouteQuery = (query: LocationQueryValue | LocationQueryValue[]) => {
if (Array.isArray(query)) {
return query.filter((v): v is string => typeof v === 'string')
} else {
return typeof query === 'string' ? [query] : ['']
}
}
11 changes: 11 additions & 0 deletions src/pages/login/LoginPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { parseRouteQuery } from '@/composable/parseRouteQuery'
import { useRoute } from 'vue-router'
const route = useRoute()
const redirectParams = parseRouteQuery(route.query.redirect)
</script>

<template>
<RouterLink :to="redirectParams[0]"> ログインする </RouterLink>
</template>
18 changes: 0 additions & 18 deletions src/pages/membership/MemberShipPageUserTypeSelect.vue

This file was deleted.

17 changes: 17 additions & 0 deletions src/pages/membership/MemberShipPageUserTypeSelector.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
import MemberShipPageUserTypeSelectorButton from './MemberShipPageUserTypeSelectorButton.vue'
</script>

<template>
<div class="flex gap-2">
<MemberShipPageUserTypeSelectorButton userType="new">
新規入部
</MemberShipPageUserTypeSelectorButton>
<MemberShipPageUserTypeSelectorButton userType="rejoin">
再入部
</MemberShipPageUserTypeSelectorButton>
<MemberShipPageUserTypeSelectorButton userType="active">
継続所属
</MemberShipPageUserTypeSelectorButton>
</div>
</template>
19 changes: 19 additions & 0 deletions src/pages/membership/MemberShipPageUserTypeSelectorButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import type { UserType } from './types/userType'
const { userType } = defineProps<{ userType: UserType }>()
const route = useRoute()
const router = useRouter()
const replaceUserTypeQuery = (userType: UserType) => {
const newQuery = { ...route.query, user_type: userType }
router.replace({ query: newQuery })
}
</script>

<template>
<button @click="replaceUserTypeQuery(userType)">
<slot></slot>
</button>
</template>
30 changes: 27 additions & 3 deletions src/pages/membership/MembershipPage.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useRoute } from 'vue-router'
import MemberShipPageUserTypeSelect from './MemberShipPageUserTypeSelect.vue'
import MemberShipPageVerifyEmailLink from '@/pages/membership/MembershipPageVerifyEmailLink.vue'
import MemberShipPageUserTypeSelector from './MemberShipPageUserTypeSelector.vue'
import MembershipPageLoginLink from './MembershipPageLoginLink.vue'
const route = useRoute()
const isLoggedIn = ref(false)
const hasIsctAddress = ref(false)
const hasCustomerObjectOnTraqId = ref(false)
const isUserTypeActive = computed(() => route.query.user_type === 'active')
</script>

<template>
<div class="flex flex-col gap-2">
<MemberShipPageUserTypeSelect />
<div>route.query.user_type: {{ route.query.user_type }}</div>
<div v-if="isLoggedIn">
<div v-if="!hasCustomerObjectOnTraqId && !hasIsctAddress">
isct アドレスの認証が必要です
<MemberShipPageVerifyEmailLink />
</div>
<div v-else>請求書情報入力へ</div>
</div>
<div v-else>
<MemberShipPageUserTypeSelector />
<div v-if="isUserTypeActive">
ログインが必要です
<MembershipPageLoginLink />
</div>
<div v-else-if="!hasIsctAddress">
isct アドレスの認証が必要です <MemberShipPageVerifyEmailLink />
</div>
<div v-else>請求書情報入力へ</div>
</div>
</div>
</template>
13 changes: 13 additions & 0 deletions src/pages/membership/MembershipPageLoginLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
const route = useRoute()
const getLoginPageURL = {
path: '/login',
query: { redirect: route.fullPath },
}
</script>

<template>
<RouterLink :to="getLoginPageURL">ログインへ</RouterLink>
</template>
13 changes: 13 additions & 0 deletions src/pages/membership/MembershipPageVerifyEmailLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
const route = useRoute()
const getVerifyEmailPageURL = {
path: '/verify-email',
query: { redirect: route.fullPath },
}
</script>

<template>
<RouterLink :to="getVerifyEmailPageURL">isct アドレスの認証へ</RouterLink>
</template>
11 changes: 11 additions & 0 deletions src/pages/verify-email/VerifyEmailPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { parseRouteQuery } from '@/composable/parseRouteQuery'
import { useRoute } from 'vue-router'
const route = useRoute()
const redirectParams = parseRouteQuery(route.query.redirect)
</script>

<template>
<RouterLink :to="redirectParams[0]"> isct アドレスを認証する </RouterLink>
</template>
10 changes: 10 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ const router = createRouter({
// which is lazy-loaded when the route is visited.
component: () => import('@/pages/membership/MembershipPage.vue'),
},
{
path: '/verify-email',
name: 'verify-email',
component: () => import('@/pages/verify-email/VerifyEmailPage.vue'),
},
{
path: '/login',
name: 'login',
component: () => import('@/pages/login/LoginPage.vue'),
},
],
})

Expand Down

0 comments on commit 01feaff

Please sign in to comment.