By following these steps, you can create a notification preferences screen where users can enable or disable email and SMS notifications separately with a single click, and where every change is saved instantly.
The “Switch” element is a state element that allows users to quickly toggle a feature or setting between on and off. It provides an intuitive and seamless user experience by enabling users to change the state with a single tap or click.
First, set up the table structure on the screen from the “Data Sources” section, then create the “UserNotificationPreferences” action from “Actions” > “New SQL Actions.” Delete the table name, retype it, and press “Enter” to ensure the correct schema name is prepended to the table name. Test and save.
Go to the “UI Design” module. Add the action you created as the “Initial Action” to your page. In the field that opens, define the values as “Default,” “User,” and “Current Userid.” Place a “Vertical Stack” on the page, add a “Label” element inside it, and type “Email Notifications” in the “Fixed Value” field. Add a “Switch” element below it. Duplicate the “Vertical Stack” block and change the text content to “SMS Notifications.” Click on the “Switch” element for “Email” and define “Action Result,” “UserNotificationPreferences,” “First,” and “Email” in the “Value” field. To save the record after making changes to the “Switch” element, use “Add Action” to add the “Save Record” action as an “onChange” action. Within the “Save Record” action, select your table and columns. Configure the “Email,” “SMS,” and “Id” fields as shown on the screen. Since a similar save process will be performed for the “SMS” field, navigate to the “Save Record” action within the “onChange” event for the “Email” field and copy it. Then, click on the second “Switch” element. To display the current setting in the “Switch” elements, configure the “SMS” definition in the “Value” field. Click the “Paste” option in the “Add Action” field to paste the “onChange” action.
When the “Preview” button is clicked, you’ll see a screen where the user can use the “Switch” elements to manage their notification preferences, and where the Email notifications and SMS notifications options displayed on the screen can be toggled on and off separately.