-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LBGG-564: Account confirmation (#580)
* Update version requirements in `package` * Update API library * Create `useConfirmAccount` composable * Create `BasicAlert` component, and add it to the default layout * Create `Loader` component * Create `/confirm-account` route * Fix rendering error messages on signup * Actually fix rendering errors on signup failure * Fix confrimation aborting, when no code or from path mismatch * Switch composable definitions to use function declarations over function expressions * Pin the latest `pnpm` version
- Loading branch information
Showing
33 changed files
with
594 additions
and
30 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script setup lang="ts"></script> | ||
|
||
<template> | ||
<div class="loader__container"> | ||
<i-svg-spinner class="loader__spinner" /> | ||
</div> | ||
</template> | ||
|
||
<style lang="postcss" scoped> | ||
.loader__container { | ||
@apply flex justify-center items-center h-screen w-full; | ||
} | ||
.loader__spinner { | ||
@apply h-20 w-20 fill-current; | ||
animation: spin 1.25s steps(9, end) infinite; | ||
@media (prefers-reduced-motion) { | ||
animation-duration: 9s; | ||
} | ||
@keyframes spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { mount, enableAutoUnmount } from '@vue/test-utils' | ||
import { useModalAlert } from 'composables/useModalAlert' | ||
import { getByClass, getByTestId, getHTMLElement } from 'root/testUtils' | ||
import BasicAlert from './BasicAlert.vue' | ||
|
||
function getBasicAlertWrapper() { | ||
return mount(BasicAlert) | ||
} | ||
|
||
beforeEach(() => { | ||
const modalAlertState = useModalAlert() | ||
modalAlertState.value = { | ||
body: 'This is a test', | ||
show: true, | ||
title: 'A test alert?', | ||
type: 'info', | ||
} | ||
}) | ||
|
||
enableAutoUnmount(afterEach) | ||
|
||
afterEach(() => { | ||
fetchMock.resetMocks() | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
describe('<BasicAlert />', () => { | ||
it('should render without crashing', () => { | ||
const wrapper = getBasicAlertWrapper() | ||
|
||
expect(wrapper.isVisible()).toBe(true) | ||
}) | ||
|
||
it('renders with the correct information', () => { | ||
const wrapper = getBasicAlertWrapper() | ||
|
||
expect( | ||
getHTMLElement(getByClass(wrapper, 'basic-modal-alert__header')) | ||
.childElementCount, | ||
).toEqual(3) | ||
expect(getByClass(wrapper, 'basic-modal-alert__title').text()).toEqual( | ||
'A test alert?', | ||
) | ||
expect(getByClass(wrapper, 'basic-modal-alert__body').text()).toEqual( | ||
'This is a test', | ||
) | ||
}) | ||
|
||
describe('when the close button is clicked', () => { | ||
it('should emit the close event', async () => { | ||
const wrapper = getBasicAlertWrapper() | ||
|
||
await getByTestId(wrapper, 'basic-modal-alert-close-button').trigger( | ||
'click', | ||
) | ||
|
||
expect(wrapper.isVisible()).toBe(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<script setup lang="ts"> | ||
import BaseModal from 'elements/modals/BaseModal/BaseModal.vue' | ||
import CloseButton from 'elements/buttons/CloseButton/CloseButton.vue' | ||
import Card from 'elements/cards/Card/Card.vue' | ||
import CardHeader from 'elements/cards/CardHeader/CardHeader.vue' | ||
import CardBody from 'elements/cards/CardBody/CardBody.vue' | ||
import { useModalAlert } from 'composables/useModalAlert' | ||
const modalAlertState = useModalAlert()?.value | ||
function close() { | ||
modalAlertState.body = '' | ||
modalAlertState.show = false | ||
modalAlertState.title = '' | ||
modalAlertState.type = '' | ||
} | ||
</script> | ||
|
||
<template> | ||
<transition | ||
v-if="modalAlertState.show" | ||
enter-active-class="transition-opacity duration-200" | ||
leave-active-class="transition-opacity duration-200" | ||
enter-to-class="opacity-100" | ||
leave-to-class="opacity-0" | ||
> | ||
<BaseModal v-show="modalAlertState.show" @close="close"> | ||
<Card | ||
id="basicModalAlert" | ||
:class="['basic-modal-alert', modalAlertState.type]" | ||
data-testid="basic-modal-alert" | ||
> | ||
<CardHeader class="basic-modal-alert__header"> | ||
<i-svg-circle-info v-if="modalAlertState.type === 'info'" /> | ||
<i-svg-circle-check v-if="modalAlertState.type === 'success'" /> | ||
<i-svg-circle-exclamation v-if="modalAlertState.type === 'error'" /> | ||
<i-svg-triangle-exclamation | ||
v-if="modalAlertState.type === 'warning'" | ||
/> | ||
<h2 class="basic-modal-alert__title"> | ||
{{ modalAlertState.title }} | ||
</h2> | ||
<CloseButton | ||
class="basic-modal-alert__close-button" | ||
data-testid="basic-modal-alert-close-button" | ||
@click.prevent="close" | ||
/> | ||
</CardHeader> | ||
<CardBody class="basic-modal-alert__body"> | ||
{{ modalAlertState.body }} | ||
</CardBody> | ||
</Card> | ||
</BaseModal> | ||
</transition> | ||
</template> | ||
|
||
<style lang="postcss" scoped> | ||
.basic-modal-alert { | ||
@apply bg-white w-full max-w-xl; | ||
svg { | ||
@apply h-5 w-5 mr-2; | ||
} | ||
&.info svg { | ||
@apply fill-blue-500; | ||
} | ||
&.success svg { | ||
@apply fill-green-500; | ||
} | ||
&.error svg { | ||
@apply fill-red-500; | ||
} | ||
&.warning svg { | ||
@apply fill-yellow-500; | ||
} | ||
& .basic-modal-alert__header { | ||
@apply flex flex-row items-center; | ||
} | ||
& .basic-modal-alert__title, | ||
& .basic-modal-alert__body { | ||
@apply flex flex-1; | ||
} | ||
& .basic-modal-alert__title { | ||
@apply text-lg font-medium py-2; | ||
@apply flex items-center; | ||
} | ||
& .basic-modal-alert__body { | ||
@apply justify-center m-8; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ApiResponse, optionalParameters, useApi } from 'composables/useApi' | ||
import { Account } from 'lib/api/Account' | ||
|
||
export async function useConfirmAccount( | ||
confirmationToken: string, | ||
opts: optionalParameters<void> = {}, | ||
): Promise<ApiResponse<void>> { | ||
const { onError, onOkay } = opts | ||
|
||
const account = new Account({ | ||
baseUrl: useRuntimeConfig().public.BACKEND_BASE_URL, | ||
}) | ||
|
||
return await useApi<void>( | ||
async () => await account.confirmUpdate(confirmationToken), | ||
{ onError, onOkay }, | ||
) | ||
} | ||
|
||
export default useConfirmAccount |
24 changes: 24 additions & 0 deletions
24
composables/api/useConfirmAccount/useConfirmAccount.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useConfirmAccount } from '.' | ||
|
||
const mockSuccessAccountConfirmation = vi.fn(() => | ||
Promise.resolve({ ok: true }), | ||
) | ||
|
||
describe('useConfirmUser', () => { | ||
describe('when everything is successful', () => { | ||
const confirmationCode = '123' | ||
|
||
it('creates a PUT request to confirm the account', async () => { | ||
vi.mock('lib/api/Account', () => ({ | ||
Account: function Account() { | ||
this.confirmUpdate = mockSuccessAccountConfirmation | ||
}, | ||
})) | ||
|
||
await useConfirmAccount(confirmationCode) | ||
|
||
expect(mockSuccessAccountConfirmation).toBeCalledTimes(1) | ||
expect(mockSuccessAccountConfirmation).toBeCalledWith(confirmationCode) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import type { UserViewModel } from 'lib/api/data-contracts' | ||
|
||
export const useCurrentUser = () => | ||
useState<UserViewModel>('current_user', () => ({ | ||
export function useCurrentUser() { | ||
return useState<UserViewModel>('current_user', () => ({ | ||
id: '', | ||
username: '', | ||
})) | ||
} | ||
|
||
export default useCurrentUser |
Oops, something went wrong.