Skip to content

Commit

Permalink
Merge pull request #895 from bcgov/feature/acceptOobInvite
Browse files Browse the repository at this point in the history
Accept OOB invite
  • Loading branch information
loneil authored Oct 25, 2023
2 parents f35754d + 5bd4125 commit 5f01a54
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
<template>
<form v-if="urlEntryStep" @submit.prevent="handleSubmit(!v$.$invalid)">
<!-- Invitation type -->
<div class="mb-3">
<span>{{ $t('connect.invitation.type') }}</span>
<div class="my-2">
<RadioButton
v-model="isOob"
input-id="type1"
name="type"
:value="false"
/>
<label for="type1" class="ml-2">{{
$t('connect.invitation.typeConnections')
}}</label>
</div>
<div>
<RadioButton
v-model="isOob"
input-id="type2"
name="type"
:value="true"
/>
<label for="type2" class="ml-2">{{
$t('connect.invitation.typeOob')
}}</label>
</div>
</div>

<div class="field">
<div class="flex justify-content-between">
<label
Expand Down Expand Up @@ -38,15 +65,21 @@
<i class="pi pi-info-circle"></i>
{{ $t('connect.acceptInvitation.supportedUrl') }}
<strong>
<!-- eslint-disable-next-line @intlify/vue-i18n/no-raw-text -->
<code>http://&lt;acapy_url&gt;?c_i=&lt;base64 encode&gt;</code>
<code>
{{
$t('connect.acceptInvitation.supportedUrlEx', [
isOob ? 'oob' : 'c_i',
])
}}
</code>
</strong>
</div>
</form>

<AcceptInviteSubmission
v-else
:invitation-string="invitationString"
:is-oob="isOob"
@closed="$emit('closed')"
/>
</template>
Expand All @@ -57,6 +90,7 @@ import { reactive, ref } from 'vue';
// PrimeVue / Validation
import Button from 'primevue/button';
import InputText from 'primevue/inputtext';
import RadioButton from 'primevue/radiobutton';
import { required, url } from '@vuelidate/validators';
import { useVuelidate } from '@vuelidate/core';
import { useToast } from 'vue-toastification';
Expand All @@ -70,6 +104,7 @@ defineEmits(['closed']);
const urlEntryStep = ref(true);
const invitationString = ref('{}');
const isOob = ref(false);
// Skip URL enter
const skipUrl = () => {
Expand Down Expand Up @@ -97,7 +132,7 @@ const handleSubmit = async (isFormValid: boolean) => {
try {
const inviteParam = paramFromUrlString(
formFields.inviteUrl,
'c_i'
isOob.value ? 'oob' : 'c_i'
) as string;
if (!inviteParam) {
throw Error('Invalid format for invitation URL');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ const { loading } = storeToRefs(useConnectionStore());
const emit = defineEmits(['closed', 'success']);
const props = defineProps({
invitationString: {
type: String,
default: '{}',
},
});
const props = withDefaults(
defineProps<{
invitationString?: string;
isOob?: boolean;
}>(),
{
invitationString: '{}',
isOob: false,
}
);
// Validation
const formFields = reactive({
Expand Down Expand Up @@ -111,7 +115,8 @@ const handleSubmit = async (isFormValid: boolean) => {
try {
await connectionStore.receiveInvitation(
formFields.invitationJson,
formFields.alias
formFields.alias,
props.isOob
);
emit('success');
// close up on success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"skipUrl": "Skip URL and use JSON",
"submit": "Accept",
"supportedUrl": "Supported URL format is",
"supportedUrlEx": "http://<acapy_url>?{0}=<base64 encode>",
"url": "Invitation URL"
},
"connections": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"skipUrl": "Skip URL and use JSON <FR>",
"submit": "Accept <FR>",
"supportedUrl": "Supported URL format is <FR>",
"supportedUrlEx": "http://<acapy_url>?{0}=<base64 encode>",
"url": "Invitation URL <FR>"
},
"connections": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"skipUrl": "Skip URL and use JSON <JA>",
"submit": "Accept <JA>",
"supportedUrl": "Supported URL format is <JA>",
"supportedUrlEx": "http://<acapy_url>?{0}=<base64 encode>",
"url": "Invitation URL <JA>"
},
"connections": {
Expand Down
11 changes: 9 additions & 2 deletions services/tenant-ui/frontend/src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,23 @@ export const useConnectionStore = defineStore('connection', () => {
return invitationData;
}

async function receiveInvitation(invite: string, alias: string) {
async function receiveInvitation(
invite: string,
alias: string,
oob: boolean
) {
console.log('> connectionStore.receiveInvitation');
error.value = null;
loading.value = true;

let acceptedData = null;
const payload = JSON.parse(invite);

const url = oob
? API_PATH.OUT_OF_BAND_RECIEVE
: API_PATH.CONNECTIONS_RECEIVE_INVITATION;
await acapyApi
.postHttp(API_PATH.CONNECTIONS_RECEIVE_INVITATION, payload, {
.postHttp(url, payload, {
params: { alias, auto_accept: true },
})
.then((res) => {
Expand Down

0 comments on commit 5f01a54

Please sign in to comment.