chore: Improve signup flow, reduce the number of inputs (#13350)
- Improved design for the Chatwoot sign up page
This commit is contained in:
@@ -22,6 +22,21 @@ const getSSOAccountPath = ({ ssoAccountId, user }) => {
|
||||
return accountPath;
|
||||
};
|
||||
|
||||
const capitalize = str =>
|
||||
str
|
||||
.split(/[._-]+/)
|
||||
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(' ');
|
||||
|
||||
export const getCredentialsFromEmail = email => {
|
||||
const [localPart, domain] = email.split('@');
|
||||
const namePart = localPart.split('+')[0];
|
||||
return {
|
||||
fullName: capitalize(namePart),
|
||||
accountName: capitalize(domain.split('.')[0]),
|
||||
};
|
||||
};
|
||||
|
||||
export const getLoginRedirectURL = ({
|
||||
ssoAccountId,
|
||||
ssoConversationId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getLoginRedirectURL } from '../AuthHelper';
|
||||
import { getLoginRedirectURL, getCredentialsFromEmail } from '../AuthHelper';
|
||||
|
||||
describe('#URL Helpers', () => {
|
||||
describe('getLoginRedirectURL', () => {
|
||||
@@ -40,4 +40,41 @@ describe('#URL Helpers', () => {
|
||||
expect(getLoginRedirectURL('7500', null)).toBe('/app/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCredentialsFromEmail', () => {
|
||||
it('should capitalize fullName and accountName from a standard email', () => {
|
||||
expect(getCredentialsFromEmail('john@company.com')).toEqual({
|
||||
fullName: 'John',
|
||||
accountName: 'Company',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle subdomains by using the first part of the domain', () => {
|
||||
expect(getCredentialsFromEmail('jane@mail.example.org')).toEqual({
|
||||
fullName: 'Jane',
|
||||
accountName: 'Mail',
|
||||
});
|
||||
});
|
||||
|
||||
it('should split by dots and capitalize each word', () => {
|
||||
expect(getCredentialsFromEmail('john.doe@acme.co')).toEqual({
|
||||
fullName: 'John Doe',
|
||||
accountName: 'Acme',
|
||||
});
|
||||
});
|
||||
|
||||
it('should omit everything after + in the local part', () => {
|
||||
expect(getCredentialsFromEmail('user+tag@startup.io')).toEqual({
|
||||
fullName: 'User',
|
||||
accountName: 'Startup',
|
||||
});
|
||||
});
|
||||
|
||||
it('should split by underscores and hyphens', () => {
|
||||
expect(getCredentialsFromEmail('first_last@my-company.com')).toEqual({
|
||||
fullName: 'First Last',
|
||||
accountName: 'My Company',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user