Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…agement into feat/990-add-multiple-redirect-urls
  • Loading branch information
MCatherine1994 committed Oct 25, 2023
2 parents 9d883ed + c565197 commit e821357
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 320 deletions.
2 changes: 2 additions & 0 deletions frontend/src/alltypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare module '@carbon/icons-vue/es/help/16';
declare module '@carbon/icons-vue/es/search/16';
declare module '@carbon/icons-vue/es/error--filled/16';
declare module '@carbon/icons-vue/es/checkmark--filled/16';
declare module '@carbon/icons-vue/es/checkmark/16';
declare module '@carbon/icons-vue/es/add/16';
declare module '@carbon/icons-vue/es/trash-can/16';
declare module '@carbon/icons-vue/es/edit/16';
Expand All @@ -19,6 +20,7 @@ declare module '@carbon/icons-vue/es/login/20';
declare module '@carbon/icons-vue/es/error--filled/20';
declare module '@carbon/icons-vue/es/warning--filled/20';
declare module '@carbon/icons-vue/es/checkmark--filled/20';
declare module '@carbon/icons-vue/es/checkmark/20';
declare module '@carbon/icons-vue/es/add/20';
declare module '@carbon/icons-vue/es/user--avatar--filled/20';
declare module '@carbon/icons-vue/es/user--avatar/20';
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/common/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const icons = {
'checkmark--filled16': defineAsyncComponent(
() => import('@carbon/icons-vue/es/checkmark--filled/16')
),
checkmark16: defineAsyncComponent(
() => import('@carbon/icons-vue/es/checkmark/16')
),
'error--filled16': defineAsyncComponent(
() => import('@carbon/icons-vue/es/error--filled/16')
),
Expand All @@ -58,6 +61,9 @@ const icons = {
'checkmark--filled20': defineAsyncComponent(
() => import('@carbon/icons-vue/es/checkmark--filled/20')
),
checkmark: defineAsyncComponent(
() => import('@carbon/icons-vue/es/checkmark/20')
),
'error--filled20': defineAsyncComponent(
() => import('@carbon/icons-vue/es/error--filled/20')
),
Expand All @@ -79,9 +85,7 @@ const icons = {
'error--filled24': defineAsyncComponent(
() => import('@carbon/icons-vue/es/error--filled/24')
),
menu20: defineAsyncComponent(
() => import('@carbon/icons-vue/es/menu/20')
),
menu20: defineAsyncComponent(() => import('@carbon/icons-vue/es/menu/20')),
} as any;
</script>

Expand Down
179 changes: 140 additions & 39 deletions frontend/src/components/grantaccess/GrantAccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ import {
selectedApplication,
selectedApplicationDisplayText,
} from '@/store/ApplicationState';
import {
domainOptions,
getGrantAccessFormData,
grantAccessFormData,
grantAccessFormRoleName,
resetGrantAccessFormData,
setGrantAccessFormData,
} from '@/store/GrantAccessDataState';
import LoadingState from '@/store/LoadingState';
import {
FamForestClientStatusType,
type FamApplicationRole,
type FamForestClient,
type IdimProxyIdirInfo,
type FamUserRoleAssignmentCreate,
} from 'fam-api';
import { IconSize } from '@/enum/IconEnum';
import { Severity } from '@/enum/SeverityEnum';
import { pushNotification } from '@/store/NotificationState';
const FOREST_CLIENT_INPUT_MAX_LENGTH = 8;
const domainOptions = { IDIR: 'I', BCEID: 'B' }; // TODO, load it from backend when backend has the endpoint.
const defaultFormData = {
domain: domainOptions.IDIR,
Expand Down Expand Up @@ -75,19 +74,14 @@ const apiServiceFactory = new ApiServiceFactory();
const applicationsApi = apiServiceFactory.getApplicationApi();
const forestClientApi = apiServiceFactory.getForestClientApi();
const idirBceidProxyApi = apiServiceFactory.getIdirBceidProxyApi();
const userRoleAssignmentApi = apiServiceFactory.getUserRoleAssignmentApi();
onMounted(async () => {
applicationRoleOptions = (
await applicationsApi.getFamApplicationRoles(
selectedApplication.value?.application_id as number
)
).data;
if (grantAccessFormData.value) {
formData.value = getGrantAccessFormData();
} else {
resetForm();
}
});
const isIdirDomainSelected = () => {
Expand Down Expand Up @@ -124,7 +118,6 @@ function resetForestClientNumberData() {
}
function resetForm() {
resetGrantAccessFormData();
formData.value = defaultFormData;
}
Expand Down Expand Up @@ -184,9 +177,9 @@ async function verifyForestClientNumber(forestClientNumber: string) {
);
}
})
.catch((error) => {
.catch(() => {
forestClientNumberVerifyErrors.value.push(
`An error occured. Client ID ${item} could not be added.`
`An error has occured. Client ID ${item} could not be added.`
);
});
}
Expand Down Expand Up @@ -216,17 +209,114 @@ function areVerificationsPassed() {
);
}
function toSummary() {
setGrantAccessFormData(formData.value, forestClientData.value);
router.push('/summary');
function toRequestPayload(
formData: any,
forestClientNumber: FamForestClient | null
) {
const request = {
user_name: formData.userId,
user_type_code: formData.domain,
role_id: formData.role_id,
...(forestClientNumber
? {
forest_client_number:
forestClientNumber.forest_client_number.padStart(
FOREST_CLIENT_INPUT_MAX_LENGTH,
'0'
),
}
: {}),
} as FamUserRoleAssignmentCreate;
return request;
}
function roleSelected(evt: any) {
let role = applicationRoleOptions.filter((role) => {
return role.role_id == evt.value;
})[0];
grantAccessFormRoleName.value = role.role_name;
resetForestClientNumberData();
async function handleSubmit() {
if (forestClientData.value.length > 0) {
const successList: string[] = [];
const warningList: string[] = [];
const errorList: string[] = [];
for (const item of forestClientData.value) {
const data = toRequestPayload(formData.value, item);
await userRoleAssignmentApi
.createUserRoleAssignment(data as FamUserRoleAssignmentCreate)
.then(() => {
successList.push(item.forest_client_number);
})
.catch((error) => {
if (error.response?.status === 409) {
warningList.push(item.forest_client_number);
} else {
errorList.push(item.forest_client_number);
}
});
}
if (successList.length > 0) {
pushNotification(
Severity.success,
`${
formData.value.userId
} was successfully added with Client IDs: ${successList.join(
', '
)}`
);
}
if (warningList.length > 0) {
pushNotification(
Severity.warning,
`${
formData.value.userId
} already exists with Client IDs: ${warningList.join(', ')}`
);
}
if (errorList.length > 0) {
pushNotification(
Severity.error,
`${
formData.value.userId
} was not added with Client IDs: ${errorList.join(', ')}`
);
}
router.push('/dashboard');
} else {
const data = toRequestPayload(formData.value, null);
await userRoleAssignmentApi
.createUserRoleAssignment(data)
.then(() => {
pushNotification(
Severity.success,
`${
formData.value.userId
} was successfully added with the role ${
getSelectedRole()?.role_name
}`
);
})
.catch((error) => {
if (error.response?.status === 409) {
pushNotification(
Severity.warning,
`${
formData.value.userId
} already exists with the role ${
getSelectedRole()?.role_name
}`
);
} else {
pushNotification(
Severity.error,
`An error has occured. ${
formData.value.userId
} could not be added with the role ${
getSelectedRole()?.role_name
}.`
);
}
});
router.push('/dashboard');
}
}
function removeForestClientFromList(index: number) {
Expand Down Expand Up @@ -374,7 +464,7 @@ function removeForestClientFromList(index: number) {
style="width: 100% !important"
v-bind="field.value"
@update:modelValue="handleChange"
@change="roleSelected($event)"
@change="resetForestClientNumberData()"
:class="{
'is-invalid': errors.role_id,
}"
Expand Down Expand Up @@ -460,7 +550,7 @@ function removeForestClientFromList(index: number) {
"
v-bind:disabled="
formData.forestClientNumber?.length <
8 ||
FOREST_CLIENT_INPUT_MAX_LENGTH ||
!!errors.forestClientNumber ||
LoadingState.isLoading.value
"
Expand All @@ -481,23 +571,28 @@ function removeForestClientFromList(index: number) {
</div>

<div class="row gy-1 my-0">
<div class="col-auto px-0">
<div class="col-auto px-0 button-stack">
<Button
type="button"
id="grantAccessSubmit"
id="grantAccessCancel"
class="mb-3 button"
label="Next"
:disabled="
!(meta.valid && areVerificationsPassed())
"
@click="toSummary()"
></Button>
<Button
class="m-3 button"
outlined
severity="secondary"
label="Cancel"
:disabled="LoadingState.isLoading.value"
@click="cancelForm()"
></Button>
<Button
type="button"
id="grantAccessSubmit"
class="m-3 button"
label="Submit Application"
:disabled="
!(meta.valid && areVerificationsPassed()) ||
LoadingState.isLoading.value
"
@click="handleSubmit()"
><Icon icon="checkmark" :size="IconSize.small"
/></Button>
</div>
</div>
</form>
Expand All @@ -522,4 +617,10 @@ function removeForestClientFromList(index: number) {
.button {
width: 7.875rem;
}
.button-stack {
Button {
width: 15rem;
}
}
</style>
Loading

0 comments on commit e821357

Please sign in to comment.