Conditional Server Action and passing results to the Page

Hi, I really need some help with this one. This is the use case:

-) a first time user signs up and go to an onboarding page;
-) user is properly logged in and user details are in the page;
-) we ask the user to input the VAT Number of his/her company;
-) we need to check if the VAT Number already exist in the Companies table and:
A) if VAT exist we show a section where user fill a form asking to another user (the company administrator) to be added as a collaborator;
B) if VAT does not exist we show a section with a form with all the company data (name, address, etc.)

I have been able to manage building a serve action that does the following steps:

  1. DB Connection
  2. Validate Data (rule does not exist in database)
  3. DB Insert (new company record with VAT Number only)
  4. Security Provider (to get the user identity)
  5. DB Update (to add the Company ID as a foreign key in User table)

First problem is that using Validate Data step I can not manage the scenario A (the VAT exist and I want to show the related specific section in the page). So I though that some condition steps should be used but then I got lost.

The idea is to query the Company table to see if the VAT number already exist (instead of using the validate action) and then somehow use a condition where IF the query results is null I do the insert of the VAT number and the update of the user, ELSE do nothing.

Second problem is that I can not figure out how to pass the information to the page so that I can show / hide the sections based on the different situation.

I understand that this is not a simple question and appreciate very much any help that you guys can give me. Thanks

Stefano

Community Page
Last updated: