Skip to content

Commit

Permalink
fix: leave current project when joining another project (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 authored Sep 5, 2024
1 parent f5e2a0e commit 6cd4774
Showing 1 changed file with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {UIActivityIndicator} from 'react-native-indicators';
import {BottomSheetModalContent} from '../BottomSheetModal';
import {useAcceptInvite} from '../../hooks/server/invites';
import {ErrorBottomSheet} from '../ErrorBottomSheet';
import {useActiveProject} from '../../contexts/ActiveProjectContext';

const m = defineMessages({
leaveProj: {
Expand Down Expand Up @@ -70,46 +71,42 @@ export const LeaveProject = ({
const [error, setError] = React.useState(false);
const [isChecked, setIsChecked] = React.useState(false);
const leaveProject = useLeaveProject();
const [combinedLoading, setCombinedLoading] = React.useState(false);
const {projectId} = useActiveProject();

function handleLeavePress() {
if (!isChecked) {
setError(true);
return;
}
setCombinedLoading(true);
// we want to accept first because the invitor will be able to cancel. this avoids the user leaving a project, and then their invite being cancelled before they were able to join.
// we want to accept first because the invitor will be able to cancel.
// this avoids the user leaving a project, and then their invite being cancelled before they were able to join.
accept.mutate(
{inviteId},
{
onSuccess: () => {
closeSheet();
setCombinedLoading(false);
leaveProject.mutate(projectId, {
onSuccess: () => {
closeSheet();
},
onError: err => {
Sentry.captureException(err);
},
});
},
// This is commented out for now and issue created: https://github.com/digidem/comapeo-mobile/issues/525
// onSuccess: () => {
// leaveProject.mutate(undefined, {
// onSuccess: () => {
// closeSheet();
// setCombinedLoading(false);
// },
// onError: err => {
// Sentry.captureException(err)
// setCombinedLoading(false);
// },
// });
// },
onError: err => {
Sentry.captureException(err);
setCombinedLoading(false);
},
},
);
}

return (
<>
{combinedLoading ? (
{accept.status === 'pending' ||
leaveProject.status === 'pending' ||
// Prevents a flicker back to non-pending UI while the sheet containing this component
// is being closed after both succeed
(accept.status === 'success' && leaveProject.status === 'success') ? (
<LeavingProjectProgress projectName={projectName} />
) : (
<BottomSheetModalContent
Expand Down

0 comments on commit 6cd4774

Please sign in to comment.