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(settings): show invite validation errors under the field (#113746)

Eleftheria Trivyzakia332b0ad4785
diff --git a/frontend/src/initKea.ts b/frontend/src/initKea.ts
index 9b219c3fecf1..aaf8b49176a7 100644
--- a/frontend/src/initKea.ts
+++ b/frontend/src/initKea.ts
@@ -122,6 +122,15 @@ generic toast would be a second one. Owned by featureFlagLogic's saveFeatureFlag
*/
const DUPLICATE_KEY_SELF_HANDLED = new Set(['saveFeatureFlag'])
+/*
+Write actions whose own UI renders a validation 400 on these attrs under the field, so the
+generic toast would be a second one. Every other failure on these actions still toasts.
+Owned by inviteLogic's inviteFieldError reducer.
+*/
+const FIELD_ERROR_SELF_HANDLED: Record<string, Set<string>> = {
+ inviteTeamMembers: new Set(['message', 'first_name']),
+}
+
const HAS_DEPENDENTS_SELF_HANDLED = new Set(['deleteDataWarehouseSavedQuery'])
/*
@@ -228,6 +237,8 @@ export function initKea({
DUPLICATE_KEY_SELF_HANDLED.has(String(actionKey))
const isHasDependentsError =
error.code === 'has_dependents' && HAS_DEPENDENTS_SELF_HANDLED.has(String(actionKey))
+ const isSelfHandledFieldError =
+ error.status === 400 && !!FIELD_ERROR_SELF_HANDLED[String(actionKey)]?.has(error.attr)
if (!errorMessage && error.status === 404) {
errorMessage = 'URL not found'
@@ -246,7 +257,8 @@ export function initKea({
isVerifiedDomainError ||
isReadOnlyImpersonationError ||
isFeatureFlagDuplicateKey ||
- isHasDependentsError
+ isHasDependentsError ||
+ isSelfHandledFieldError
) {
// These are handled by their own dedicated toasts elsewhere.
errorMessage = null
diff --git a/frontend/src/scenes/settings/organization/InviteModal.tsx b/frontend/src/scenes/settings/organization/InviteModal.tsx
index d4dfe661d2ec..3fd42c8d907e 100644
--- a/frontend/src/scenes/settings/organization/InviteModal.tsx
+++ b/frontend/src/scenes/settings/organization/InviteModal.tsx
@@ -309,7 +309,7 @@ export function InviteTeamMatesComponent({
hideProjectAccessSelector?: boolean
}): JSX.Element {
const { preflight } = useValues(preflightLogic)
- const { invitesToSend, inviteContainsOwnerLevel } = useValues(inviteLogic)
+ const { invitesToSend, inviteContainsOwnerLevel, messageError, recipientNameError } = useValues(inviteLogic)
const { appendInviteRow, updateMessage, setIsInviteConfirmed, ensureAllMembersLoaded } = useActions(inviteLogic)
useOnMountEffect(ensureAllMembersLoaded)
@@ -355,6 +355,11 @@ export function InviteTeamMatesComponent({
isDeletable={areInvitesDeletable}
/>
))}
+ {recipientNameError && (
+ <div className="text-danger text-xs" data-attr="invite-name-error">
+ {recipientNameError}
+ </div>
+ )}
<div className="mt-2 flex justify-end">
{areInvitesCreatable && (
@@ -374,6 +379,11 @@ export function InviteTeamMatesComponent({
placeholder="Tell your teammates why you're inviting them to PostHog"
onChange={(e) => updateMessage(e)}
/>
+ {messageError && (
+ <div className="text-danger text-xs mt-1" data-attr="invite-message-error">
+ {messageError}
+ </div>
+ )}
</div>
)}
diff --git a/frontend/src/scenes/settings/organization/inviteLogic.test.ts b/frontend/src/scenes/settings/organization/inviteLogic.test.ts
index 7954b04af5ce..a8051e990a47 100644
--- a/frontend/src/scenes/settings/organization/inviteLogic.test.ts
+++ b/frontend/src/scenes/settings/organization/inviteLogic.test.ts
@@ -35,4 +35,20 @@ describe('inviteLogic', () => {
canSubmit: !isExistingMember,
})
})
+
+ it('shows a message validation error under the field until the message changes', async () => {
+ logic.actions.inviteTeamMembersFailure('', {
+ status: 400,
+ attr: 'message',
+ code: 'invalid_url',
+ detail: 'URLs are not allowed in this field.',
+ })
+ await expectLogic(logic).toMatchValues({ messageError: 'URLs are not allowed in this field.' })
+
+ logic.actions.updateInviteAtIndex({ first_name: 'Jo' }, 0)
+ await expectLogic(logic).toMatchValues({ messageError: 'URLs are not allowed in this field.' })
+
+ logic.actions.updateMessage('no link this time')
+ await expectLogic(logic).toMatchValues({ messageError: null })
+ })
})
diff --git a/frontend/src/scenes/settings/organization/inviteLogic.ts b/frontend/src/scenes/settings/organization/inviteLogic.ts
index c41d80f500d5..4bcd36607d0d 100644
--- a/frontend/src/scenes/settings/organization/inviteLogic.ts
+++ b/frontend/src/scenes/settings/organization/inviteLogic.ts
@@ -26,6 +26,14 @@ export interface InviteRowState {
private_project_access: Array<{ id: number; level: AccessControlLevel.Member | AccessControlLevel.Admin }>
}
+export interface InviteFieldError {
+ attr: string
+ detail: string
+}
+
+// The bulk endpoint collapses per-row errors to the first one, so a row field can't be pinned to its row.
+const INLINE_ERROR_FIELDS = new Set(['message', 'first_name'])
+
const EMPTY_INVITE: InviteRowState = {
target_email: '',
first_name: '',
@@ -45,6 +53,7 @@ export interface inviteLogicValues {
existingMemberInviteRows: boolean[]
hasExistingMemberInvite: boolean
inviteContainsOwnerLevel: boolean
+ inviteFieldError: InviteFieldError | null
invitedTeamMembersInternal: OrganizationInviteType[]
invitedTeamMembersInternalLoading: boolean
invites: OrganizationInviteType[]
@@ -54,6 +63,7 @@ export interface inviteLogicValues {
isInviteModalShown: boolean
isInviting: boolean
message: string
+ messageError: string | null
projectAccessControls: Record<
number,
{
@@ -61,6 +71,7 @@ export interface inviteLogicValues {
}
>
projectAccessControlsLoading: boolean
+ recipientNameError: string | null
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -196,6 +207,8 @@ export interface inviteLogicMeta {
) => boolean
availableProjects: (currentOrganization: null | import('~/types').OrganizationType) => any[]
isInviting: (invitedTeamMembersInternalLoading: boolean) => boolean
+ messageError: (inviteFieldError: InviteFieldError | null) => string | null
+ recipientNameError: (inviteFieldError: InviteFieldError | null) => string | null
}
}
@@ -364,6 +377,21 @@ export const inviteLogic = kea<inviteLogicType>([
setIsInviteConfirmed: (_, { inviteConfirmed }) => inviteConfirmed,
},
],
+ inviteFieldError: [
+ null as InviteFieldError | null,
+ {
+ inviteTeamMembersFailure: (_, { errorObject }) =>
+ INLINE_ERROR_FIELDS.has(errorObject?.attr) && errorObject?.detail
+ ? { attr: errorObject.attr, detail: errorObject.detail }
+ : null,
+ inviteTeamMembersSuccess: () => null,
+ updateMessage: (state) => (state?.attr === 'message' ? null : state),
+ updateInviteAtIndex: (state, { payload }) =>
+ state?.attr === 'first_name' && 'first_name' in payload ? null : state,
+ deleteInviteAtIndex: (state) => (state?.attr === 'first_name' ? null : state),
+ hideInviteModal: () => null,
+ },
+ ],
})),
selectors({
inviteContainsOwnerLevel: [
@@ -421,6 +449,16 @@ export const inviteLogic = kea<inviteLogicType>([
(selectors) => [selectors.invitedTeamMembersInternalLoading],
(invitedTeamMembersInternalLoading: boolean) => invitedTeamMembersInternalLoading,
],
+ messageError: [
+ (selectors) => [selectors.inviteFieldError],
+ (inviteFieldError: InviteFieldError | null): string | null =>
+ inviteFieldError?.attr === 'message' ? inviteFieldError.detail : null,
+ ],
+ recipientNameError: [
+ (selectors) => [selectors.inviteFieldError],
+ (inviteFieldError: InviteFieldError | null): string | null =>
+ inviteFieldError?.attr === 'first_name' ? inviteFieldError.detail : null,
+ ],
}),
listeners(({ values, actions }) => ({
inviteTeamMembersSuccess: (): void => {