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

lib-user: Add DeactivatedGroup component for active membership with deactivated group #6256

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
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 @@ -16,9 +16,11 @@ import {
} from '@hooks'

import {
createPanoptesMembership
createPanoptesMembership,
deletePanoptesMembership
} from '@utils'

import DeactivatedGroup from './components/DeactivatedGroup'
import { getUserGroupStatus } from './helpers/getUserGroupStatus'

function deleteJoinTokenParam() {
Expand Down Expand Up @@ -59,6 +61,8 @@ function GroupContainer({
isMutating: createGroupMembershipLoading,
trigger: createGroupMembership
} = useSWRMutation(membershipKey, createPanoptesMembership)
// define user_group membership delete mutation
const { trigger: deleteMembership, isMutating: deleteMembershipLoading } = useSWRMutation(membershipKey, deletePanoptesMembership)
// extract user_group active membership
const newGroupMembership = newGroupMembershipData?.memberships?.[0]
const membership = newGroupMembership || membershipsData?.memberships?.[0]
Expand Down Expand Up @@ -133,6 +137,8 @@ function GroupContainer({
joinToken
})

const activeMembershipDeactivatedGroup = activeMembershipRole && groupError?.status === 404

return (
<>
{showJoinNotification && (
Expand All @@ -144,7 +150,22 @@ function GroupContainer({
toast
/>
)}
{status ? (
{activeMembershipDeactivatedGroup ? (
<Layout>
<ContentBox
align='center'
direction='column'
justify='center'
pad='large'
>
<DeactivatedGroup
deleteMembership={deleteMembership}
deleteMembershipLoading={deleteMembershipLoading}
membershipId={activeMembership.id}
/>
</ContentBox>
</Layout>
) : status ? (
<Layout>
<ContentBox
align='center'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Loader, SpacedText } from '@zooniverse/react-components'
import { Box } from 'grommet'
import { SubtractCircle } from 'grommet-icons'
import { bool, func, string } from 'prop-types'

import { HeaderButton } from '@components/shared'

const DEFAULT_HANDLER = () => true

function DeactivatedGroup({
deleteMembership = DEFAULT_HANDLER,
deleteMembershipLoading = false,
membershipId
}) {
async function handleGroupMembershipLeave ({
membershipId
}) {
await deleteMembership({ membershipId }, {
revalidate: true
})

window.location.href = '/'
}

return (
<Box
align='center'
direction='column'
gap='medium'
>
<SpacedText uppercase={false}>
This is a deactivated group.
Please leave the group or contact the group administrator if you believe this is an error.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this message, I think it's ok, but let me know what you think.

</SpacedText>
{deleteMembershipLoading ? (
<Loader />
) : (
<HeaderButton
key='leave-group-button'
icon={<SubtractCircle color='white' size='small' />}
label='Leave Group'
onClick={() => handleGroupMembershipLeave({
membershipId,
})}
/>
)}
</Box>
)
}

DeactivatedGroup.propTypes = {
deleteMembership: func,
deleteMembershipLoading: bool,
membershipId: string.isRequired
}

export default DeactivatedGroup