Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sign-in/sign-up form shows success even if API was not sent successfully [SPMVP-6214] #187

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 0 # disable shallow checkout, chromatic need git history
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
- name: Install dependencies
run: yarn
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
- name: publish package
run: |
Expand All @@ -46,7 +46,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
- name: publish package
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
- run: yarn

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
- run: yarn
- run: yarn test --coverage
11 changes: 9 additions & 2 deletions src/PaywallSystem.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts" setup>
import { ApolloError } from '@apollo/client/core'
import { useEventBus, useVModel } from '@vueuse/core'
import { computed, provide, ref, watch } from 'vue'
import type {
Expand Down Expand Up @@ -91,11 +92,15 @@ const profile = computed(() => {
async function handleSignup(email: string, customArticleType?: string) {
const checkExistEmailAndShowDialog = async (showDialogType: UserDialogType) => {
const result = await onSignup(email)
if (result && result?.data.signUpSubscriber) {
if (result instanceof ApolloError) {
const result = await onLogin({ email })
if (!result) dialogType.value = 'error'
modalVisible.value = true
} else if (result && result?.data.signUpSubscriber) {
dialogType.value = showDialogType
visible.value = true
} else {
onLogin({ email })
dialogType.value = 'error'
modalVisible.value = true
}
}
Expand Down Expand Up @@ -201,6 +206,8 @@ function onConfirmModal() {
dialogType.value = 'shareToTwitter'
modalVisible.value = true
}, 300)
} else if (dialogType.value === 'error') {
dialogType.value = 'welcome'
}
}

Expand Down
1 change: 1 addition & 0 deletions src/components/UserDialog/UserDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const dialogMap: Record<UserDialogType | '', Component | undefined> = {
subscribe: AccountDetail,
confirmation: OnlyButton,
shareToTwitter: undefined,
error: undefined,
'': undefined,
}

Expand Down
1 change: 1 addition & 0 deletions src/components/UserDialog/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type UserDialogType =
| 'subscribe'
| 'confirmation'
| 'shareToTwitter'
| 'error'

export interface SubscriberInput {
email?: string
Expand Down
7 changes: 7 additions & 0 deletions src/composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMutation } from '@vue/apollo-composable'
import { useStorage } from '@vueuse/core'
import gql from 'graphql-tag'
import { type Ref, computed } from 'vue'
import { ApolloError } from '@apollo/client/core'

export type AuthAPI = ReturnType<typeof useAuth>

Expand Down Expand Up @@ -58,6 +59,12 @@ export function useAuth(tokenRef: Ref<string | null> = useStorage('test-token',
return result
}
} catch (e) {
if (e instanceof ApolloError) {
const errorMessage = e.graphQLErrors[0]?.message
if (errorMessage === 'Bad Request.') {
return e
}
}
// eslint-disable-next-line no-console
console.log('e: ', e)
}
Expand Down
5 changes: 5 additions & 0 deletions src/modal-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ export const modalTexts: Record<string, ModalText> = {
title: 'Spread the word',
sub: 'If you want to help __PUBLICATION_NAME__ even more, share your reason for subscribing.',
},
error: {
title: 'An error occurred',
sub: 'Please retry later.',
button: 'Close',
},
}
Loading