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

Update handleDelete of Collaborators in Console #6491

Merged
merged 1 commit into from
Sep 1, 2023
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
5 changes: 3 additions & 2 deletions pkg/webui/containers/collaborator-form/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ const useCollaboratorData = (entity, entityId, collaboratorId, tts) => {
const currentUserId = useSelector(selectUserId)
const isCurrentUser = isUser && currentUserId === collaboratorId
const updateCollaborator = patch => tts[sdkServices[entity]].Collaborators.update(entityId, patch)
const removeCollaborator = collaboratorIds =>
tts[sdkServices[entity]].Collaborators.remove(entityId, collaboratorIds)
const removeCollaborator = (isUser, collaboratorIds) => {
tts[sdkServices[entity]].Collaborators.remove(isUser, entityId, collaboratorIds)
}

return {
collaborator,
Expand Down
14 changes: 2 additions & 12 deletions pkg/webui/containers/collaborator-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ const CollaboratorForm = props => {
removeCollaborator,
} = useCollaboratorData(entity, entityId, collaboratorId, tts)

const collaboratorType = isCollaboratorUser ? 'user' : 'organization'

const [submitError, setSubmitError] = useState(undefined)
const navigate = useNavigate()
const error = submitError || passedError
Expand Down Expand Up @@ -127,18 +125,10 @@ const CollaboratorForm = props => {
[navigate, update, updateCollaborator],
)
const handleDelete = useCallback(async () => {
const collaborator_ids = {
[`${collaboratorType}_ids`]: {
[`${collaboratorType}_id`]: collaboratorId,
},
}
const updatedCollaborator = {
ids: collaborator_ids,
}
setSubmitError(undefined)

try {
await removeCollaborator(updatedCollaborator)
await removeCollaborator(isCollaboratorUser, collaboratorId)
toast({
message: sharedMessages.collaboratorDeleteSuccess,
type: toast.types.SUCCESS,
Expand All @@ -147,7 +137,7 @@ const CollaboratorForm = props => {
} catch (error) {
setSubmitError(error)
}
}, [collaboratorId, collaboratorType, navigate, removeCollaborator])
}, [collaboratorId, isCollaboratorUser, navigate, removeCollaborator])

const initialValues = React.useMemo(() => {
if (!collaborator) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/webui/lib/store/actions/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ export const [
},
] = createRequestActions(
DELETE_COLLABORATOR_BASE,
(parentType, parentId) => ({
(parentType, parentId, collaboratorId, isUser) => ({
parentType,
parentId,
collaboratorId,
isUser,
}),
(parentType, parentId, selector) => ({ selector }),
(parentType, parentId, collaboratorId, isUser, selector) => ({ selector }),
)
11 changes: 6 additions & 5 deletions pkg/webui/lib/store/middleware/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ export default tts => {
const deleteCollaboratorLogic = createRequestLogic({
type: collaborators.DELETE_COLLABORATOR,
process: async ({ action }) => {
const { parentType, parentId } = action.payload

const result = await tts.Clients.Collaborators.update(parentType, parentId)

return result
const { parentType, parentId, collaboratorId, isUser } = action.payload
return await tts[entitySdkServiceMap[parentType]].Collaborators.remove(
isUser,
parentId,
collaboratorId,
)
},
})

Expand Down
1 change: 1 addition & 0 deletions sdk/js/src/service/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Applications {
get: 'application_ids.application_id',
list: 'application_ids.application_id',
set: 'application_ids.application_id',
delete: 'application_ids.application_id',
},
})
this.Webhooks = new Webhooks(api.ApplicationWebhookRegistry)
Expand Down
1 change: 1 addition & 0 deletions sdk/js/src/service/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Clients {
get: 'client_ids.client_id',
list: 'client_ids.client_id',
set: 'client_ids.client_id',
delete: 'client_ids.client_id',
},
})

Expand Down
16 changes: 14 additions & 2 deletions sdk/js/src/service/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,20 @@ class Collaborators {
return await this.add(entityId, data)
}

async remove(entityId, data) {
return await this.add(entityId, { ...data, rights: [] })
async remove(isUser, entityId, collaboratorId) {
const entityIdRoute = this._parentRoutes.delete
const collaboratorIdRoute = isUser
? 'collaborator_ids.user_ids.user_id'
: 'collaborator_ids.organization_ids.organization_id'

const result = await this._api.DeleteCollaborator({
routeParams: {
[entityIdRoute]: entityId,
[collaboratorIdRoute]: collaboratorId,
},
})

return Marshaler.payloadSingleResponse(result)
}
}

Expand Down
1 change: 1 addition & 0 deletions sdk/js/src/service/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Gateways {
get: 'gateway_ids.gateway_id',
list: 'gateway_ids.gateway_id',
set: 'gateway_ids.gateway_id',
delete: 'gateway_ids.gateway_id',
},
})
autoBind(this)
Expand Down
1 change: 1 addition & 0 deletions sdk/js/src/service/organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Organizations {
get: 'organization_ids.organization_id',
list: 'organization_ids.organization_id',
set: 'organization_ids.organization_id',
delete: 'organization_ids.organization_id',
},
})
autoBind(this)
Expand Down
Loading