Skip to content

Commit

Permalink
fix: project leaving inconsistencies (#853)
Browse files Browse the repository at this point in the history
* Uses a state variable and use effect in the bottom sheet modal related to project invitation so the success modal shows properly.
  • Loading branch information
cimigree authored Nov 21, 2024
1 parent 001a75e commit b87c15e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/frontend/sharedComponents/BottomSheetModal/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const Content = ({
<View
style={[
styles.container,
fullScreen ? {height: '100%'} : {maxHeight: window.height * 0.8},
fullScreen ? {height: window.height} : {maxHeight: window.height * 0.8},
]}>
<View style={[styles.infoContainer, fullScreen && {flex: 1}]}>
{icon ? <View style={styles.iconContainer}>{icon}</View> : null}
Expand Down
32 changes: 25 additions & 7 deletions src/frontend/sharedComponents/ProjectInviteBottomSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const ProjectInviteBottomSheet = ({

const [leaveModalState, setLeaveModalState] =
React.useState<LeaveProjectModalState>('AlreadyOnProj');
const [inviteModalVisible, setInviteModalVisible] = React.useState(false);

const invite = invites[0];

Expand All @@ -64,9 +65,23 @@ export const ProjectInviteBottomSheet = ({
const accept = useAcceptInvite();
const reject = useRejectInvite();

if (invite && !inviteIsOpen && enabledForCurrentScreen) {
openInviteSheet();
}
React.useEffect(() => {
if (
(invite || acceptedInvite) &&
!inviteModalVisible &&
enabledForCurrentScreen
) {
setInviteModalVisible(true);
}
}, [invite, acceptedInvite, inviteModalVisible, enabledForCurrentScreen]);

React.useEffect(() => {
if (inviteModalVisible && !inviteIsOpen) {
openInviteSheet();
} else if (!inviteModalVisible && inviteIsOpen) {
closeInviteSheet();
}
}, [inviteModalVisible, inviteIsOpen, openInviteSheet, closeInviteSheet]);

if (currentInviteCanceled && leaveIsOpen) {
closeLeaveSheet();
Expand All @@ -77,20 +92,20 @@ export const ProjectInviteBottomSheet = ({
reject.mutate(invite, {
onSuccess: () => {
if (invites.length <= 1) {
closeInviteSheet();
setInviteModalVisible(false);
}
},
});
}
if (invites.length <= 1) {
closeInviteSheet();
setInviteModalVisible(false);
}
}

function handleCanceledInvite() {
resetCacheAndClearCanceled();
if (invites.length <= 1) {
closeInviteSheet();
setInviteModalVisible(false);
}
}

Expand All @@ -115,6 +130,7 @@ export const ProjectInviteBottomSheet = ({
accept.reset();
reject.reset();
acceptedInvite?.remove();
setInviteModalVisible(false);
}}>
{currentInviteCanceled ? (
<InviteCanceledBottomSheetContent
Expand All @@ -123,7 +139,9 @@ export const ProjectInviteBottomSheet = ({
/>
) : acceptedInvite ? (
<InviteSuccessBottomSheetContent
closeSheet={closeInviteSheet}
closeSheet={() => {
setInviteModalVisible(false);
}}
projectName={acceptedInvite.value.projectName}
/>
) : (
Expand Down

0 comments on commit b87c15e

Please sign in to comment.