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

feat: for signup set make organization name optional and set a default one #21083

Merged
merged 15 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
27 changes: 26 additions & 1 deletion cypress/e2e/signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('Signup', () => {
})

it('Can create user account', () => {
cy.intercept('POST', '/api/signup/').as('signupRequest')

const email = `new_user+${Math.floor(Math.random() * 10000)}@posthog.com`
cy.get('[data-attr=signup-email]').type(email).should('have.value', email)
cy.get('[data-attr=password]').type('12345678').should('have.value', '12345678')
Expand All @@ -51,6 +53,29 @@ describe('Signup', () => {
cy.get('[data-attr=signup-role-at-organization]').contains('Engineering')
cy.get('[data-attr=signup-submit]').click()

cy.wait('@signupRequest').then((interception) => {
expect(interception.request.body).to.have.property('organization_name')
expect(interception.request.body.organization_name).to.equal('Hogflix SpinOff')
})

// lazy regex for a guid
cy.location('pathname').should('match', /\/verify_email\/[a-zA-Z0-9_.-]*/)
})
it('Can create user account without an organization name', () => {
cy.intercept('POST', '/api/signup/').as('signupRequest')

const email = `new_user+${Math.floor(Math.random() * 10000)}@posthog.com`
cy.get('[data-attr=signup-email]').type(email).should('have.value', email)
cy.get('[data-attr=password]').type('12345678').should('have.value', '12345678')
cy.get('[data-attr=signup-start]').click()
cy.get('[data-attr=signup-first-name]').type('Alice').should('have.value', 'Alice')
cy.get('[data-attr=signup-submit]').click()

cy.wait('@signupRequest').then((interception) => {
expect(interception.request.body).to.have.property('organization_name')
expect(interception.request.body.organization_name).to.equal("Alice's Organization")
})

// lazy regex for a guid
cy.location('pathname').should('match', /\/verify_email\/[a-zA-Z0-9_.-]*/)
})
Expand All @@ -74,7 +99,7 @@ describe('Signup', () => {
cy.get('.Toastify [data-attr="error-toast"]').contains('Inactive social login session.')
})

it.only('Shows redirect notice if redirecting for maintenance', () => {
it('Shows redirect notice if redirecting for maintenance', () => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { urlToAction } from 'kea-router'
import api from 'lib/api'
import { CLOUD_HOSTNAMES, FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import posthog from 'posthog-js'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { urls } from 'scenes/urls'

Expand Down Expand Up @@ -83,14 +84,20 @@ export const signupLogic = kea<signupLogicType>([
role_at_organization: '',
referral_source: '',
} as SignupForm,
errors: ({ first_name, organization_name }) => ({
errors: ({ first_name }) => ({
first_name: !first_name ? 'Please enter your name' : undefined,
zlwaterfield marked this conversation as resolved.
Show resolved Hide resolved
organization_name: !organization_name ? 'Please enter your organization name' : undefined,
}),
submit: async (payload, breakpoint) => {
breakpoint()
try {
const res = await api.create('api/signup/', { ...values.signupPanel1, ...payload })
const res = await api.create('api/signup/', {
zlwaterfield marked this conversation as resolved.
Show resolved Hide resolved
...values.signupPanel1,
...payload,
organization_name: payload.organization_name || `${payload.first_name}'s Organization`,
})
if (!payload.organization_name) {
posthog.capture('default organization name set')
}
location.href = res.redirect_url || '/'
} catch (e) {
actions.setSignupPanel2ManualErrors({
Expand Down
Loading