1
1
import { useWizard , Wizard } from '../../common' ;
2
- import { useCoreOrganization , useCoreUser , useOrganizationProfileContext } from '../../contexts' ;
2
+ import {
3
+ useCoreOrganization ,
4
+ useCoreOrganizationList ,
5
+ useCoreUser ,
6
+ useOrganizationProfileContext ,
7
+ } from '../../contexts' ;
3
8
import type { LocalizationKey } from '../../customizables' ;
4
9
import { localizationKeys , Text } from '../../customizables' ;
5
10
import {
@@ -12,22 +17,39 @@ import {
12
17
} from '../../elements' ;
13
18
import { useRouter } from '../../router' ;
14
19
import { handleError , useFormControl } from '../../utils' ;
20
+ import { organizationListParams } from '../OrganizationSwitcher/utils' ;
15
21
import { OrganizationProfileBreadcrumbs } from './OrganizationProfileNavbar' ;
16
22
17
- export const LeaveOrganizationPage = ( ) => {
23
+ const useLeaveWithRevalidations = ( leavePromise : ( ( ) => Promise < any > ) | undefined ) => {
18
24
const card = useCardState ( ) ;
19
25
const { navigateAfterLeaveOrganization } = useOrganizationProfileContext ( ) ;
26
+ const { userMemberships, userInvitations } = useCoreOrganizationList ( {
27
+ userMemberships : organizationListParams . userMemberships ,
28
+ userInvitations : organizationListParams . userInvitations ,
29
+ } ) ;
30
+
31
+ return ( ) =>
32
+ card
33
+ . runAsync ( async ( ) => {
34
+ await leavePromise ?.( ) ;
35
+ } )
36
+ . then ( ( ) => {
37
+ void userMemberships . revalidate ?.( ) ;
38
+ void userInvitations . revalidate ?.( ) ;
39
+ void navigateAfterLeaveOrganization ( ) ;
40
+ } ) ;
41
+ } ;
42
+
43
+ export const LeaveOrganizationPage = ( ) => {
20
44
const { organization } = useCoreOrganization ( ) ;
21
45
const user = useCoreUser ( ) ;
22
46
23
- if ( ! organization ) {
47
+ const leaveOrg = useLeaveWithRevalidations ( organization ? ( ) => user . leaveOrganization ( organization . id ) : undefined ) ;
48
+
49
+ if ( ! organization || ! user ) {
24
50
return null ;
25
51
}
26
52
27
- const leave = ( ) => {
28
- return card . runAsync ( user . leaveOrganization ( organization . id ) ) . then ( navigateAfterLeaveOrganization ) ;
29
- } ;
30
-
31
53
return (
32
54
< ActionConfirmationPage
33
55
organizationName = { organization ?. name }
@@ -42,24 +64,20 @@ export const LeaveOrganizationPage = () => {
42
64
successMessage = { localizationKeys (
43
65
'organizationProfile.profilePage.dangerSection.leaveOrganization.successMessage' ,
44
66
) }
45
- onConfirmation = { leave }
67
+ onConfirmation = { leaveOrg }
46
68
/>
47
69
) ;
48
70
} ;
49
71
50
72
export const DeleteOrganizationPage = ( ) => {
51
- const card = useCardState ( ) ;
52
- const { navigateAfterLeaveOrganization } = useOrganizationProfileContext ( ) ;
53
- const { organization } = useCoreOrganization ( ) ;
73
+ const { organization , membership } = useCoreOrganization ( ) ;
74
+
75
+ const deleteOrg = useLeaveWithRevalidations ( organization ?. destroy ) ;
54
76
55
- if ( ! organization ) {
77
+ if ( ! organization || ! membership ) {
56
78
return null ;
57
79
}
58
80
59
- const deleteOrg = ( ) => {
60
- return card . runAsync ( organization . destroy ( ) ) . then ( navigateAfterLeaveOrganization ) ;
61
- } ;
62
-
63
81
return (
64
82
< ActionConfirmationPage
65
83
organizationName = { organization ?. name }
0 commit comments