Finishing touches (Blazor)
In this final part of the CRM tutorial we will add a few final features that will make the CRM application more polished.
- Customize the navigation.
- Show the current user picture.
- Allow the current user to update his personal details - first name, last name and picture.
- Create custom design for the login page.
Customize the navigation
We will rearrange the navigation, create a hierarchy, and add icons.
The application navigation typically lives in the Main layout. Layouts are special pages that define common UI components that are shared between multiple pages.
- Open the Main layout in Radzen.
- Select the PanelMenu component. Click the … button to open the Navigation item editor.
- By default it doesn’t display any items because it shows all pages that are marked as “include in navigation” (add and edit pages are excluded by default).
- Click the refresh button to create items for all pages in the application.
- Remove the Opportunity statuses, Task Statuses and Task Types pages. We will add them later under a common parent.
- Move the Home page to the top so it appears first. Set Text to
Dashboard
and Icon tohome
. - Move the Contacts page so it appears second. Set the Icon to
perm_contact_calendar
. - Make the Tasks page third and set the Icon to
work
. - Make Opportunities fourth and set the Icon to
shopping_cart
. - Add a new item with Text
Settings
and Icon:settings
. Set the Visible property to${Security.IsInRole("Sales Manager")}
. This makes this item visible only to members of theSales Manager
role. - Add a child item with Text
Opportunity Statuses
and pick theOpportunity Statuses
page from the Path dropdown. - Then add another child with Text
Task Types
and pick theTask Types
page from the Path dropdown. - Finally add one last child for the
Task Statuses
page.
Now when a member of the Sales Manager
role logs in she would see this navigation.
Members of the Sales Representative
role will see this (note that the Settings menu item is not present).
Show the current user picture
By default the Main layout has a ProfileMenu component which allows users to logout or update their profile. Let’s customize the ProfileMenu to show the current user name and profile picture.
- Select the ProfileMenu component.
- Click the Edit template button.
- Delete the Gravatar component.
- Drag and drop a Label component.
- Set the Text of the Label to
${Security.User.FirstName}
. - Duplicate the Label. Set its Text to
${Security.User.LastName}
. - Drag and drop an Image. Set Path to
${Security.User.Picture}
. Set Width and Height to32px
and BorderRadius to16px
. - End template editing.
If you run the application from Radzen you will see the current user picture and name in the top right corner.
Update user details
When you enable security for a Radzen application one of the scaffolded pages is Profile (also accessible from the ProfileMenu component in the top right corner).
By default it allows the current user to change their password. In the CRM application we have extended the AspNetUsers table with three new columns - FirstName
, LastName
, Picture
and we want the
user to be able to change them.
Create the UI
Now let’s create the UI.
- Open the Profile page in Radzen.
- Drag and drop a Tabs component.
- Add two items:
Personal
andPassword
. - Select the
Password
tab and move the TemplateForm there. - Delete the now empty Row.
- Select the
Personal
tab and drag and drop a new TemplateForm inside. Set its Data property to${user}
. - Set the Text of the label to
First Name
. Set the Value of the TextBox to${user.FirstName}
. Set the Text of the validator toFirst Name is required
. - Duplicate the first row of the form. Set the Text of the label to
Last Name
. Set Component totextBox0
. Set the Value of the TextBox to${user.LastName}
. Set the Text of the validator toLast Name is required
. Set Component totextbox0
. - Duplicate the second row of the form. Delete the TextBox and drop a FileInput.
Set the Text of the label to
Picture
. Set Component tofileInput0
. Set the Value of the FileInput to${user.Picture}
and its Display style property toblock
. Set the Text of the validator toPicture is required
. Set Component tofileInput0
.
The final step is to update the personal data when the user submits the form.
- Go back to Radzen.
- Add a new handler for the form Submit event.
- Ivoke the
Security.updateUser
custom method. Set theId
parameter- Set the Id parameter to
${Security.User.Id}
- Set the User parameter to
${user}
- Set the Id parameter to
- Display a notification in the Then event to let the user know that their details have been updated.
Custom login page
Finally let’s create a custom login page by editing both the Login layout and page.
Login layout
We will add a background image that will cover the whole page. Also we will add the CRM application logo.
Add the assets
Radzen allows you to use images seamlessly. For this demo we will use a background and logo. Download those files and add them as assets in the application.
Set the background image
- Open the Login layout.
- Drag an Image component and drop it before the existing row component.
- Set the Path of the image to login-background.png (click … to use the asset picker).
- Set Width and Height to
100%
. Set Position toabsolute
. Set Top and Left to0
. This will make the image cover the whole page.
Center the row
We now want to center the login form in the page (both horizontally and vertically).
- Select the Row component.
- Set Horizontal Alignment and Vertical Alignment to
Center
. - Go to the Style tab. Set Position to
absolute
, Top, Right, Bottom and Left to0
. Set Margin to0
.
Specify column settings
- Select the Column component.
- Set the XL size to
3
units, LG to4
, MD to5
and SM to8
. - Set Vertical Alignment and Horizontal Alignment to
None
. - Go to the Style tab and set Padding to
0px
. - Select the Card component. Go to the Style tab of the property grid and set the top Margin to
0
.
Add logo
- Drag an Image component and drop it in the Card component.
- Set Path to
logo.png
. - Set Width and Height to
128px
. Set BorderRadius to64px
. This will make the logo a circle. - Let’s center the image. Set Display to
block
. Set Right and Left Margin toauto
. - Now let’s make the image pop out of the card a bit. Set Top Margin to
-72px
.
Login page
Let’s now customize the Login page by using a TemplateForm instead of the Login component.
Create the login form
- Open the Login page.
- Delete the existing Login component and its parent row and column.
- Drag and drop a TemplateForm then delete its content.
- Drag and drop a TextBox inside the TemplateForm. Set its Name to
Username
and Width to100%
. - Drag a Label before the TextBox.
Set its Text to
Username
and pickUsername
from the Component dropdown. Set Display toblock
so the TextBox starts on the next line. Set top Margin to16px
. - Drag and drop a Password. Set its Name to
Password
and Width to100%
. - Drag and drop a Label. Set Text and Component to
Password
. Set Display toblock
. Set top Margin to16px
. - Drag and drop a Button. Set Text to
Login
, ButtonType tosubmit
, Width to100%
and top Margin to16px
.
Perform the login
Now to actually perform the login.
- Set the Action property of the TemplateForm to
/Account/Login
. - Set Method to
post
.
That is all!
Complete source
The complete source of this application (with a few additional changes that are mostly cosmetic) is available for server-side Blazor and for client-side WebAssembly Blazor in the Radzen github repository.