Skip to content

Commit

Permalink
tenant config handling
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <lucasoneil@gmail.com>
  • Loading branch information
loneil committed May 30, 2023
1 parent 73a7812 commit 0d3d120
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
<Column :expander="true" header-style="width: 3rem" />
<Column :sortable="false" :header="$t('common.actions')">
<template #body="{ data }">
<EditSettings
:connection-id="data.connection_id"
:connection-name="data.alias"
/>
<EditConfig :id="data.tenant_id" />
<EditContact :connection-id="data.connection_id" />
</template>
</Column>
Expand Down Expand Up @@ -76,7 +73,7 @@ import { storeToRefs } from 'pinia';
import { TABLE_OPT, API_PATH } from '@/helpers/constants';
import { formatDateLong } from '@/helpers';
import RowExpandData from '@/components/common/RowExpandData.vue';
import EditSettings from './editSettings/editSettings.vue';
import EditConfig from './editConfig/editConfig.vue';
const toast = useToast();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
:modal="true"
@update:visible="handleClose"
>
<EditSettingsForm @success="$emit('success')" @closed="handleClose" />
<EditConfigForm
:id="props.id"
@success="$emit('success')"
@closed="handleClose"
/>
</Dialog>
</div>
</template>
Expand All @@ -25,10 +29,15 @@ import { ref } from 'vue';
import Button from 'primevue/button';
import Dialog from 'primevue/dialog';
// Custom Components
import EditSettingsForm from './editSettingsForm.vue';
import EditConfigForm from './editConfigForm.vue';
defineEmits(['success']);
// Props
const props = defineProps<{
id: string;
}>();
const displayModal = ref(false);
const openModal = async () => {
// Kick of the loading asyncs (if needed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
</template>

<script setup lang="ts">
// Types
import { TenantConfig } from '@/types/acapyApi/acapyInterface';
// Vue
import { reactive, ref } from 'vue';
// PrimeVue / Validation
Expand All @@ -45,6 +48,12 @@ const toast = useToast();
const emit = defineEmits(['closed', 'success']);
const { loading } = storeToRefs(useInnkeeperTenantsStore());
const innkeeperTenantsStore = useInnkeeperTenantsStore();
// Props
const props = defineProps<{
id: string;
}>();
// Validation
const formFields = reactive({
Expand All @@ -67,7 +76,15 @@ const handleSubmit = async (isFormValid: boolean) => {
}
try {
alert('API Call TBD');
await innkeeperTenantsStore.updateTenantConfig(props.id, {
connect_to_endorser: [
{
endorser_alias: 'endorser',
ledger_id: 'bcovrin-test',
},
],
create_public_did: ['bcovrin-test'],
});
toast.success('Tenant Settings Updated');
emit('success');
// close up on success
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="canConnectEndorser" class="my-1">
<div v-if="canConnectEndorser || hasEndorserConn" class="my-1">
<p class="my-1">{{ $t('profile.connectTenantToEndorser') }}</p>
<InputSwitch
:model-value="hasEndorserConn"
Expand Down Expand Up @@ -65,7 +65,8 @@ const canConnectEndorser = computed(() => {
return (
allowedConnection.endorser_alias ===
endorserInfo.value?.endorser_name &&
allowedConnection.ledger_id === config.value.ariesDetails.ledgerName
allowedConnection.ledger_id ===
config.value.frontend?.ariesDetails?.ledgerName
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="canRegisterDid" class="true-1">
<div v-if="canRegisterDid || hasPublicDid" class="true-1">
<p class="my-1">{{ $t('profile.registerPublicDid') }}</p>
<InputSwitch
:model-value="hasPublicDid"
Expand Down Expand Up @@ -29,7 +29,7 @@
</template>

<script setup lang="ts">
import { computed, ref } from 'vue';
import { computed } from 'vue';
import Accordion from 'primevue/accordion';
import AccordionTab from 'primevue/accordiontab';
import InputSwitch from 'primevue/inputswitch';
Expand All @@ -55,7 +55,7 @@ const canRegisterDid = computed(() => {
// Will enhance once mult-ledger supported
const allowedLedger = tenantConfig.value.create_public_did[0];
// If the tenant is allowed to register on the configured ledger
return allowedLedger === config.value.ariesDetails.ledgerName;
return allowedLedger === config.value.frontend?.ariesDetails?.ledgerName;
}
return false;
});
Expand Down
3 changes: 3 additions & 0 deletions services/tenant-ui/frontend/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export const API_PATH = {
INNKEEPER_TOKEN: '/innkeeper/token',
INNKEEPER_TENANTS: '/innkeeper/tenants/',
INNKEEPER_TENANT: (id: string) => `/innkeeper/tenants/${id}`,
INNKEEPER_TENANT_CONFIG: (id: string) => `/innkeeper/tenants/${id}/config`,
INNKEEPER_RESERVATIONS: '/innkeeper/reservations/',
INNKEEPER_RESERVATIONS_APPROVE: (id: string) =>
`/innkeeper/reservations/${id}/approve`,
INNKEEPER_RESERVATIONS_CONFIG: (id: string) =>
`/innkeeper/reservations/${id}/config`,
INNKEEPER_RESERVATIONS_DENY: (id: string) =>
`/innkeeper/reservations/${id}/deny`,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Types
import { TenantConfig } from '@/types/acapyApi/acapyInterface';

import { defineStore, storeToRefs } from 'pinia';
import { computed, ref, Ref } from 'vue';
import axios from 'axios';
Expand All @@ -18,10 +21,10 @@ export const useInnkeeperTenantsStore = defineStore('innkeeperTenants', () => {
const { config } = storeToRefs(useConfigStore());

// state
const tenants: Ref<any> = ref(null);
const reservations: Ref<any[]> = ref([]);
const loading: Ref<boolean> = ref(false);
const error: Ref<string | null> = ref(null);
const loading: Ref<boolean> = ref(false);
const reservations: Ref<any[]> = ref([]);
const tenants: Ref<any> = ref(null);

// getters
const currentReservations = computed(() =>
Expand Down Expand Up @@ -155,6 +158,30 @@ export const useInnkeeperTenantsStore = defineStore('innkeeperTenants', () => {
});
}

// Update the config for a Tenant
async function updateTenantConfig(id: string, payload: TenantConfig) {
error.value = null;
loading.value = true;

try {
await acapyApi.putHttp(API_PATH.INNKEEPER_TENANT_CONFIG(id), payload);
// Reload the tenants list after updating
await listTenants();
} catch (err: any) {
error.value = err;
} finally {
loading.value = false;
}

if (error.value != null) {
// throw error so $onAction.onError listeners can add their own handler
throw error.value;
}
}

// private methods

// Helper method to send email
function _sendStatusEmail(payload: any) {
// Separately dispatch a non-blocking call to send the status update email
// If this fails we won't raise any error to the UI
Expand All @@ -179,6 +206,7 @@ export const useInnkeeperTenantsStore = defineStore('innkeeperTenants', () => {
denyReservation,
listTenants,
listReservations,
updateTenantConfig,
};
});

Expand Down

0 comments on commit 0d3d120

Please sign in to comment.