1- import { Dialog , Image , Separator } from '@raystack/apsara/* ' ;
1+ import { Dialog , Image , Separator , toast } from '@raystack/apsara' ;
22import styles from '../../organization.module.css' ;
3- import { Flex , Text } from '@raystack/apsara/v1' ;
3+ import { Button , Flex , Text } from '@raystack/apsara/v1' ;
44import cross from '~/react/assets/cross.svg' ;
55import { useNavigate , useParams } from '@tanstack/react-router' ;
6+ import { useFrontier } from '~/react/contexts/FrontierContext' ;
7+ import { useState } from 'react' ;
8+ import { V1Beta1Policy } from '~/api-client' ;
69
710export const RemoveProjectMember = ( ) => {
11+ const [ isLoading , setIsLoading ] = useState ( false ) ;
12+
13+ const { client } = useFrontier ( ) ;
814 const navigate = useNavigate ( {
915 from : '/projects/$projectId/$membertype/$memberId/remove'
1016 } ) ;
1117
12- const { projectId } = useParams ( {
18+ const { projectId, memberId } = useParams ( {
1319 from : '/projects/$projectId/$membertype/$memberId/remove'
1420 } ) ;
21+
22+ async function onConfirm ( ) {
23+ setIsLoading ( true ) ;
24+ try {
25+ const {
26+ // @ts -ignore
27+ data : { policies = [ ] }
28+ } = await client ?. frontierServiceListPolicies ( {
29+ project_id : projectId ,
30+ user_id : memberId
31+ } ) ;
32+
33+ const deletePromises = policies . map ( ( p : V1Beta1Policy ) =>
34+ client ?. frontierServiceDeletePolicy ( p . id as string )
35+ ) ;
36+
37+ await Promise . all ( deletePromises ) ;
38+ navigate ( {
39+ to : '/projects/$projectId' ,
40+ params : { projectId } ,
41+ state : { refetch : true }
42+ } ) ;
43+ toast . success ( 'Member removed' ) ;
44+ } catch ( err : any ) {
45+ toast . error ( 'Something went wrong' , {
46+ description : err . message
47+ } ) ;
48+ } finally {
49+ setIsLoading ( false ) ;
50+ }
51+ }
52+
1553 return (
1654 < Dialog open = { true } >
1755 < Dialog . Content
18- style = { { padding : 0 , maxWidth : '600px ' , width : '100%' , zIndex : '60' } }
56+ style = { { padding : 0 , maxWidth : '400px ' , width : '100%' , zIndex : '60' } }
1957 overlayClassname = { styles . overlay }
2058 >
2159 < Flex justify = "between" style = { { padding : '16px 24px' } } >
@@ -37,6 +75,34 @@ export const RemoveProjectMember = () => {
3775 />
3876 </ Flex >
3977 < Separator />
78+ < Flex direction = "column" gap = "medium" style = { { padding : '24px' } } >
79+ < Text size = { 4 } >
80+ Are you sure you want to remove this member from the project?
81+ </ Text >
82+ </ Flex >
83+ < Separator />
84+ < Flex justify = "end" style = { { padding : 'var(--pd-16)' } } gap = "medium" >
85+ < Button
86+ size = "normal"
87+ variant = "secondary"
88+ onClick = { ( ) => navigate ( { to : '/members' } ) }
89+ data-test-id = "frontier-sdk-remove-project-member-cancel-btn"
90+ disabled = { isLoading }
91+ >
92+ Cancel
93+ </ Button >
94+ < Button
95+ size = "normal"
96+ variant = "danger"
97+ onClick = { onConfirm }
98+ data-test-id = "frontier-sdk-remove-project-member-confirm-btn"
99+ disabled = { isLoading }
100+ loading = { isLoading }
101+ loaderText = "Removing"
102+ >
103+ Remove
104+ </ Button >
105+ </ Flex >
40106 </ Dialog . Content >
41107 </ Dialog >
42108 ) ;
0 commit comments