-
Notifications
You must be signed in to change notification settings - Fork 13
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
Strr2 - Draft Terms of Service #260
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,7 +1,19 @@ | ||
export default defineNuxtRouteMiddleware(() => { | ||
export default defineNuxtRouteMiddleware(async (to) => { | ||
const { isAuthenticated } = useKeycloak() | ||
const tosStore = useTosStore() | ||
const localePath = useLocalePath() | ||
|
||
if (!isAuthenticated.value) { | ||
return navigateTo({ path: useLocalePath()('/auth/login') }) | ||
return navigateTo(localePath('/auth/login')) | ||
} | ||
|
||
// check if tos exists or is not accepted | ||
if (tosStore.tos.isTermsOfUseAccepted === undefined || !tosStore.tos.isTermsOfUseAccepted) { | ||
await tosStore.getTermsOfUse() // load latest tos if no tos found in store or not accepted | ||
|
||
// return to tos page if not accepted | ||
if (!tosStore.tos.isTermsOfUseAccepted) { | ||
return navigateTo({ path: localePath('/auth/tos'), query: { return: to.fullPath } }) | ||
} | ||
} | ||
}) |
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,127 @@ | ||
<script setup lang="ts"> | ||
import type { FormError } from '#ui/types' | ||
const { $sanitize } = useNuxtApp() | ||
const { t } = useI18n() | ||
const tosStore = useTosStore() | ||
const strrModal = useStrrModals() | ||
const route = useRoute() | ||
|
||
// page stuff | ||
useHead({ | ||
title: t('strr.title.login') | ||
}) | ||
|
||
setBreadcrumbs([ | ||
{ label: t('label.bcregDash'), to: useRuntimeConfig().public.registryHomeURL + 'dashboard' }, | ||
{ label: 'Terms of Use' } | ||
]) | ||
|
||
const checkboxRef = ref(null) | ||
const formRef = ref() // typing not working here | ||
const tosDivRef = ref<HTMLDivElement | null>(null) | ||
|
||
const { bottom: tosBottom } = useElementBounding(tosDivRef) | ||
const { top: formTop } = useElementBounding(formRef) | ||
|
||
// track if user has scrolled to bottom of page | ||
const hasReachedBottom = computed(() => formTop.value >= tosBottom.value) | ||
|
||
// reset form errors if user reaches bottom of page | ||
watch(hasReachedBottom, (newVal) => { | ||
if (newVal) { | ||
formRef.value?.clear() | ||
} | ||
}) | ||
|
||
const state = reactive({ | ||
agreeToTerms: undefined | ||
}) | ||
|
||
const validate = (state: { agreeToTerms: boolean | undefined }): FormError[] => { | ||
const errors: FormError[] = [] | ||
|
||
if (!state.agreeToTerms && !hasReachedBottom.value) { | ||
errors.push({ path: 'agreeToTerms', message: 'You must scroll to the bottom of this page to accept the tos' }) | ||
return errors | ||
} | ||
|
||
if (!state.agreeToTerms) { | ||
errors.push({ path: 'agreeToTerms', message: 'You must accept the Terms of Use to continue' }) | ||
} | ||
|
||
return errors | ||
} | ||
|
||
async function submitTermsOfUse () { | ||
try { | ||
tosStore.loading = true | ||
await tosStore.patchTermsOfUse() | ||
await navigateTo(route.query.return as string) | ||
} catch { | ||
// TODO: handle patch errors | ||
} finally { | ||
tosStore.loading = false | ||
} | ||
} | ||
</script> | ||
<template> | ||
<!-- eslint-disable vue/no-v-html --> | ||
<div class="relative mx-auto flex w-full flex-col items-center sm:max-w-screen-sm md:max-w-screen-md"> | ||
<ConnectTypographyH1 | ||
class="sticky top-0 w-full border-b border-bcGovGray-500 bg-bcGovColor-gray1 pb-2 pt-4 text-center sm:pt-8" | ||
text="Terms of Use" | ||
/> | ||
|
||
<div | ||
v-if="tosStore.tos.termsOfUse" | ||
ref="tosDivRef" | ||
class="prose prose-bcGov max-w-full break-words" | ||
v-html="$sanitize(tosStore.tos.termsOfUse)" | ||
/> | ||
|
||
<!-- TODO: display fallback content if tos fails to load --> | ||
|
||
<UForm | ||
ref="formRef" | ||
class="sticky bottom-0 flex w-full flex-col items-start justify-between | ||
gap-4 border-t border-bcGovGray-500 bg-bcGovColor-gray1 py-4 sm:flex-row sm:items-center sm:gap-0 sm:pb-8" | ||
:state | ||
:validate="validate" | ||
@submit="submitTermsOfUse()" | ||
> | ||
<UFormGroup | ||
name="agreeToTerms" | ||
> | ||
<UCheckbox | ||
ref="checkboxRef" | ||
v-model="state.agreeToTerms" | ||
:disabled="!hasReachedBottom || tosStore.loading" | ||
label="I have read and accept the Terms of Use" | ||
/> | ||
<template #error="{ error }"> | ||
<span :class="{ 'text-red-500': error, 'text-base': !hasReachedBottom }"> | ||
{{ error }} | ||
</span> | ||
</template> | ||
</UFormGroup> | ||
<div class="flex w-full gap-4 sm:w-fit"> | ||
<UButton | ||
class="flex-1 sm:flex-none" | ||
:ui="{ base: 'flex justify-center items-center'}" | ||
label="Accept Terms of Use" | ||
aria-label="Accept Terms of Use, You must scroll to the bottom to accept the terms of use checkbox" | ||
type="submit" | ||
:loading="tosStore.loading" | ||
/> | ||
<UButton | ||
class="flex-1 sm:flex-none" | ||
:ui="{ base: 'flex justify-center items-center'}" | ||
:label="$t('btn.decline')" | ||
variant="outline" | ||
:disabled="tosStore.loading" | ||
@click="strrModal.openConfirmDeclineTosModal()" | ||
/> | ||
</div> | ||
</UForm> | ||
</div> | ||
</template> |
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,63 @@ | ||
interface TOSPatchResponse { | ||
isTermsOfUseAccepted: boolean | ||
termsOfUseAcceptedVersion: string | ||
} | ||
|
||
interface TOSGetResponse { | ||
isTermsOfUseAccepted: boolean | ||
termsOfUseAcceptedVersion: string | null | ||
termsOfUseCurrentVersion: string | ||
termsOfUse: string | ||
} | ||
|
||
// TODO: make this generic for the core layer? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think this would be good there. Might be good to prefix this with 'connect' if we're going to do that. For now we could put it in the strr base layer and figure out the kinks before moving it |
||
// will require the following api calls | ||
// await $authApi('/users/@me') <-- this is breaking for Sergey, will need to fix this before adding to core layer | ||
// await $authApi('/documents/termsofuse') | ||
|
||
export const useTosStore = defineStore('strr/terms-of-service', () => { | ||
const { $strrApi } = useNuxtApp() | ||
const loading = ref<boolean>(false) | ||
const tos = ref<TOSGetResponse>({} as TOSGetResponse) | ||
|
||
async function getTermsOfUse ():Promise<void> { | ||
try { | ||
loading.value = true | ||
tos.value = await $strrApi<TOSGetResponse>('/users/tos') | ||
} catch { | ||
// TODO: handle errors | ||
} finally { | ||
loading.value = false | ||
} | ||
} | ||
|
||
// form submit event | ||
async function patchTermsOfUse () { | ||
const res = await $strrApi<TOSPatchResponse>('/users/tos', { | ||
method: 'PATCH', | ||
body: { | ||
istermsaccepted: true, | ||
termsversion: tos.value.termsOfUseCurrentVersion | ||
} | ||
}) | ||
|
||
// update tos accepted to match patch response or middleware will run again | ||
tos.value.isTermsOfUseAccepted = res.isTermsOfUseAccepted | ||
} | ||
|
||
function $reset () { | ||
sessionStorage.removeItem('strr/terms-of-service') // required to reset store on logout | ||
loading.value = false | ||
tos.value = {} as TOSGetResponse | ||
} | ||
|
||
return { | ||
loading, | ||
tos, | ||
getTermsOfUse, | ||
patchTermsOfUse, | ||
$reset | ||
} | ||
}, | ||
{ persist: true } // this will persist in session storage so we only load the tos once per session | ||
) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to add that to https://github.com/bcgov/STRR/blob/main/strr-platform-web/devops/vaults.env
or I can in another PR?