Commit 1ab2ae3c authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

feat: allow to request to access on org unit from list

parent 73d256b9
......@@ -185,4 +185,4 @@
{{'organizationalUnit.requestToBeMember' | translate}}
</button>
</ng-template>
</form>
</form>
\ No newline at end of file
......@@ -6,9 +6,14 @@ import {
import {MatDialog} from "@angular/material/dialog";
import {ActivatedRoute} from "@angular/router";
import {NotificationHelper} from "@app/features/preservation-space/notification/helper/notification.helper";
import {OrgunitRequestAccessDialog} from "@app/features/preservation-space/organizational-unit/components/dialogs/orgunit-request-access/orgunit-request-access.dialog";
import {orgUnitActionNameSpace} from "@app/features/preservation-space/organizational-unit/stores/organizational-unit.action";
import {OrganizationalUnitStateModel} from "@app/features/preservation-space/organizational-unit/stores/organizational-unit.state";
import {OrganizationalUnit} from "@models";
import {AppUserState} from "@app/stores/user/app-user.state";
import {
NotificationType,
OrganizationalUnit,
} from "@models";
import {Navigate} from "@ngxs/router-plugin";
import {
Actions,
......@@ -21,9 +26,12 @@ import {RoutesEnum} from "@shared/enums/routes.enum";
import {DataTableActions} from "@shared/models/data-table-actions.model";
import {RouterExtService} from "@shared/services/router-ext.service";
import {SecurityService} from "@shared/services/security.service";
import {SharedNotificationAction} from "@shared/stores/notification/shared-notification.action";
import {tap} from "rxjs/operators";
import {
isNullOrUndefined,
OrderEnum,
ResourceState,
TRANSLATE,
} from "solidify-frontend";
......@@ -78,6 +86,12 @@ export class OrgunitListRoutable extends SharedAbstractListRoutable<Organization
placeholder: TRANSLATE("crud.list.action.goToReceivedRequestNotification"),
displayOnCondition: model => this._securityService.isRootOrAdmin() || this._securityService.isMemberOfOrgUnit(model.resId),
},
{
logo: "announcement",
callback: model => this.requestToBeMember(model.resId),
placeholder: TRANSLATE("organizationalUnit.requestToBeMember"),
displayOnCondition: model => !this._securityService.isRootOrAdmin() && !this._securityService.isMemberOfOrgUnit(model.resId),
},
{
logo: "account_circle",
callback: model => null,
......@@ -139,4 +153,30 @@ export class OrgunitListRoutable extends SharedAbstractListRoutable<Organization
goToDeposit(orgUnit: OrganizationalUnit): void {
this._store.dispatch(new Navigate([RoutesEnum.deposit, orgUnit.resId]));
}
requestToBeMember(orgUnitResId: string): void {
this.subscribe(this._dialog.open(OrgunitRequestAccessDialog, {
minWidth: "500px",
}).afterClosed().pipe(
tap((message: string | undefined) => {
if (isNullOrUndefined(message)) {
return;
}
this.sendRequestToBeMember(orgUnitResId, message);
}),
));
}
private sendRequestToBeMember(orgUnitResId: string, message: string): void {
this._store.dispatch(new SharedNotificationAction.Create({
model: {
emitter: ResourceState.currentSnapshot(this._store, AppUserState),
notifiedOrgUnit: {
resId: orgUnitResId,
},
message: message,
notificationType: NotificationType.NotificationTypeEnum.JOIN_ORG_UNIT_REQUEST,
},
}));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment