How do I build a workflow that allows for User Signup and automatic Company creation?
In this episode, we'll learn how to build a workflow in the Signup Component to allow for Company Users to create accounts, create companies, and set an automatic connection to the Company using:
- Form Processes
- Rules
- Pipes
Features Discussed:
-
Form Component (Time: 4:22)
Learn how forms are processed within the application. -
Connection Fields (Time: 8:05)
Learn how to structure circular relationships between users and companies, ensuring accurate representation without infinite loops or data redundancy. For example, a user may be associated with multiple companies, each managed by specific users. -
Signup Component (Time: 10:04)
Learn how to add extra fields to a signup form and apply display rules based on user selections. For instance, selecting "I’m an Admin" prompts additional fields like "Company Name" and "Admin Code." -
Tadabase Text Utilities (Time: 15:05)
Learn how to use Regex (Regular Expression) masks to manipulate and extract text data. For example, applying the pattern /(.+)@/ to tim@tadabase.io extracts the domain tadabase.io, useful for formatting and validation. -
Tadabase Rest API (Time: 16:50)
Learn how to apply filters based on a single value field by passing parameters like table ID and filter value, allowing for precise data views. For instance, filter records to show only those containing the value tadabase.io. -
Record Rules (Time: 19:37)
Get Domain: Learn to use a Regex mask pipe to extract domains from email addresses. For example, with user@tadabase.io, the Regex /^(.+)@/ extracts tadabase.io.
Insert Connected Companies: Learn to set up a record rule that associates new users with companies by inserting the company's domain into their records..
Get Domain and Insert Connected Companies: Learn to extract a domain from an email and insert connected companies using Regex Mask and record rules for automation.
Update Admin and Staff Roles: Learn to dynamically update user roles when creating accounts, assigning roles based on whether the user selects 'Admin' or 'Staff.'
Filter by Single Field and Connect to Company: Learn to filter records using the Tadabase REST API and connect them to a company based on the filtered results. -
Validation Rule with Tadabase Rest API (Time: 36:40)
Learn how to use the Tadabase REST API for validation.
Trigger a Pipe : Set up the API to filter records and validate fields like email domains.
Set Parameters : Define parameters including table ID and filter value.
Add a Condition : Set conditions based on validation outcomes, such as ensuring a minimum number of records.
Display Validation Message : Trigger a custom message to inform users if validation fails.
Transcript Summary
Introduction
Welcome back to this week's episode of Build It with Tadabase. Today, we're diving into a complex workflow for user signups, specifically for admins and staff members. This suggestion comes from Ivan—thanks for the great idea!
The core concept is that when an admin signs up, a company record is created and connected to that user. Subsequently, when staff members sign up, they are automatically connected to that company using the domain of their email address.
Workflow Overview
The signup process works as follows:
- Admin Signups: When an admin signs up, a company record is created using the admin's domain name (extracted from their email address) and connected to their user account.
- Staff Signups: For any subsequent staff member signups, the domain from their email is matched to the existing company, automatically connecting them to that company.
This entire process hinges on identifying the domain from the user's email and handling the logic around it, including creating and connecting company and user records.
Key Components
1. Database Processes:
- We'll be working extensively with database processes and form handling, specifically looking at how forms are processed when submitted.
- Signup components, which are essentially specialized forms, are crucial to this process.
2. Rules:
- We'll be leveraging various rules, such as record rules and validation rules, to manage when certain actions occur during the signup process.
- Rules help ensure that, for example, companies can't be created multiple times or staff members can't create companies.
3. Pipes:
- Pipes will be used to extract the domain from the user's email and check for existing company records based on that domain.
Final Product
The final product is the signup form, where everything is happening behind the scenes. Whether you sign up as an admin or a staff member, the logic to connect users to companies is automatically handled through display rules, validation rules, and record rules.
If an admin signs up, they create both their user account and a company record. If a staff member signs up, they are connected to the existing company, provided their email domain matches the one already associated with the company.
Data Structure
- User Record:
- Standard fields include name, email, status, and role.
- Additional fields include:
- A connection to the company table.
- A radio field to select if the user is an admin or staff member.
- An
admin code
field for added security. - A
domain
field to store the domain extracted from the email.
- Company Record:
- Standard fields include company name and a connection back to the user who created it.
- The
domain
field will store the domain extracted from the admin's email for later validation.
Building the Signup Workflow
1. Display Rules:
- The form includes fields for "company name" and "admin code" that only display when a user selects the admin role.
- If a user selects "I'm an admin," these fields become both visible and required.
2. Record Rules:
- When the form is submitted, the first record rule runs a pipe to extract the domain from the email and save it to the
domain
field. - The second rule inserts a connected company record if the user is an admin.
- The third and fourth rules set the user's role based on their selection (admin or staff).
- The final rule connects the user to the appropriate company based on their email domain.
3. Validation Rules:
- Company Existence: If a staff member signs up, their domain is checked against the existing company records. If no match is found, an error is triggered.
- Unique Company Creation: Validation prevents admins from creating duplicate companies based on the company name.
- Admin Code Validation: Ensures that only users who know the admin code can create companies, preventing unauthorized staff from signing up as admins.
Testing the Workflow
- Admin Signup:
- An admin signs up, creates both a user and company record, and the domain is extracted and saved correctly.
- Staff Signup:
- A staff member signs up using an email with the same domain as the admin, automatically connecting them to the existing company.
Admin Code and Validation Rules
We’ll first set up a validation rule to check for an admin code. If the admin code entered does not match our records, the form will fail with a message like: "Sorry, that admin code doesn't match our records."
Next, we’ll set a validation rule for checking the company name. The company name is unique and will only be filled out if the user is an admin. This rule ensures that admins are the only ones who can submit the form and create new company records.
Unique Company Name and Domain
For admins, we are setting a rule that checks if both the company name and the domain are unique. If they are not unique, the validation will fail, preventing the creation of duplicate companies. However, it is possible for admins to create different companies, as long as the combination of the company name and domain is unique.
Workflow Process Overview
Here’s a summary of the workflow:
- Admins and Staff Signup Form: Admins must input a valid admin code to submit the form. If the company name and domain are already in use, the form will not submit.
- Creating a Company Record: The company record is created if the admin successfully passes validation.
- Stopping Duplicate Companies: The validation rule prevents admins from creating the same company twice.
Setting Up the Signup Page
In the signup page, we set up validation rules to handle admin-specific conditions:
- If the admin code is incorrect, the form fails validation.
- If the same company name and domain are used, the form fails with a message saying the company already exists.
Detailed Record Rules Setup
We set up five record rules:
- Retrieving the Domain Name: This rule runs for both admins and staff. It extracts the domain from the user's email and saves it to the user record.
- Creating a Company Record: This rule applies only to admins. It creates a connected company record and saves the admin as the creator.
- Updating the User Role: This rule adjusts the user role based on the admin or staff selection.
- Connecting the User to a Company: This rule updates the user's company connection based on the domain matching an existing company in the database.
Protecting the Signup Form with Validation Rules
We implement three key validation rules:
- Email Domain Matching: Ensures that the email domain matches an existing company for staff users.
- Admin Code: Requires admins to input a correct code to trigger form submission.
- Company Name and Domain Uniqueness: Prevents duplicate company creation by checking the uniqueness of the company name and domain combination.
Corrections and Final Adjustments
In a later segment, we correct a few validation rules:
- The first validation rule should only apply to staff, checking the company based on the domain.
- The third validation rule, checking the uniqueness of the company name and domain, should only apply to admins.
After making these changes, the signup form works correctly with the proper validation and record rules in place.
Conclusion
That wraps up this episode of Build It with Tadabase. We’ve covered how to set up a signup form with validation and record rules, ensuring that the workflow functions as intended. If you have any questions about this specific workflow, feel free to reach out. Thanks for watching, and I'll see you next week!
We'd love to hear your feedback.