Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: leave current project when joining another project (#646) #670

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading