Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(cohorts): stop reducer error on remove person from cohort (#70624)

posthog[bot]c76df462a2cb
diff --git a/frontend/src/scenes/cohorts/cohortEditLogic.ts b/frontend/src/scenes/cohorts/cohortEditLogic.ts
index bd8a733be982..0ce1d357f7dd 100644
--- a/frontend/src/scenes/cohorts/cohortEditLogic.ts
+++ b/frontend/src/scenes/cohorts/cohortEditLogic.ts
@@ -127,8 +127,6 @@ export interface cohortEditLogicValues {
personsToCreateStaticCohort: Record<string, boolean>
pollTimeout: number | null
query: DataTableNode
- removePersonFromCohort: any
- removePersonFromCohortLoading: boolean
showCohortErrors: boolean
staticCohortMode: StaticCohortMode
usedIn: CohortUsedInResponseApi | null
@@ -260,24 +258,6 @@ export interface cohortEditLogicActions {
removePersonFromCohort: (personId: string) => {
personId: string
}
- removePersonFromCohortFailure: (
- error: string,
- errorObject?: any
- ) => {
- error: string
- errorObject?: any
- }
- removePersonFromCohortSuccess: (
- removePersonFromCohort: void,
- payload?: {
- personId: string
- }
- ) => {
- removePersonFromCohort: void
- payload?: {
- personId: string
- }
- }
removePersonFromCreateStaticCohort: (personId: string) => {
personId: string
}
@@ -1026,27 +1006,6 @@ export const cohortEditLogic = kea<cohortEditLogicType>([
},
],
- removePersonFromCohort: [
- null as any,
- {
- removePersonFromCohort: async ({ personId }) => {
- if (!values.cohort.id || values.cohort.id === 'new') {
- throw new Error('Cannot remove person from unsaved cohort')
- }
-
- try {
- await api.cohorts.removePersonFromCohort(values.cohort.id, personId)
- lemonToast.success('Person removed from cohort')
- } catch (error: any) {
- throw error
- }
- // Refresh cohort data + count
- actions.refreshPersonsData()
- actions.updateCohortCount()
- },
- },
- ],
-
usedIn: [
null as CohortUsedInResponseApi | null,
{
@@ -1113,6 +1072,25 @@ export const cohortEditLogic = kea<cohortEditLogicType>([
deleteCohort: () => {
cohortsModel.actions.deleteCohort({ id: values.cohort.id, name: values.cohort.name })
},
+ removePersonFromCohort: async ({ personId }) => {
+ if (!values.cohort.id || values.cohort.id === 'new') {
+ lemonToast.error('Cannot remove a person from an unsaved cohort')
+ return
+ }
+
+ try {
+ await api.cohorts.removePersonFromCohort(values.cohort.id, personId)
+ } catch (error: any) {
+ lemonToast.error(error.detail || 'Failed to remove person from cohort')
+ posthog.captureException(error, { feature: 'cohort-remove-person' })
+ return
+ }
+
+ lemonToast.success('Person removed from cohort')
+ // Refresh cohort data + count
+ actions.refreshPersonsData()
+ actions.updateCohortCount()
+ },
submitCohortFailure: () => {
scrollToFormError({
extraErrorSelectors: ['.CohortCriteriaRow__Criteria--error'],