import { Component , OnInit , Input , Output , EventEmitter } from '@angular/core' ; import { Router } from '@angular/router' ; import { GroupService } from '../../services/groups/group.service' ; import { RequestsService } from "../../services/requests/requests.service" ; import { ContextService } from "../../services/context.service" ; import { MatSnackBar } from "@angular/material" ; import { UtilsService } from "../../services/utils.service" ; @ Component ( { selector : 'app-request-access-modal' , templateUrl : './request-access-modal.component.html' , styleUrls : [ './request-access-modal.component.scss' ] } ) export class RequestAccessModalComponent { constructor ( private router , private requestsService , private context , private utils , public snackBar , private groupService ) { } private _show ; @ Output ( ) showChange = new EventEmitter ( ) ; @ Input ( ) group ; @ Input ( ) set show ( value ) { this . _show = value ; this . showChange . emit ( this . _show ) ; } get show ( ) { return this . _show ; } close ( ) { this . show = false ; } requestAccess ( ) { this . groupService . addMemberToGroup ( this . group . id , this . context . getUser ( ) ) . then ( ( response ) => { console . log ( 'Request Access Response: ' , response ) ; let user = this . context . getUser ( ) ; user . proposals . push ( response . id ) ; this . close ( ) ; this . utils . defaultSnackBar ( 'Request Sent' ) ; } ) ; } }