Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@rendermode InteractiveServer

@using CulinaryCommand.Data.Entities
@using CulinaryCommand.Models
@using Microsoft.AspNetCore.WebUtilities

@inject NavigationManager Nav
Expand All @@ -24,15 +25,21 @@ else
{
<EditForm Model="@model" OnValidSubmit="Submit">
<DataAnnotationsValidator />
<ValidationSummary />

<div class="mb-3">
<label class="form-label">New Password</label>
<InputText class="form-control" @bind-Value="model.Password" type="password" />
<ValidationMessage For="@(() => model.Password)" />
<small class="text-muted d-block mt-1">
Must meet password requirements (length + character rules).
</small>
</div>

<div class="mb-3">
<label class="form-label">Confirm Password</label>
<InputText class="form-control" @bind-Value="model.ConfirmPassword" type="password" />
<ValidationMessage For="@(() => model.ConfirmPassword)" />
</div>

<button class="btn btn-success" disabled="@submitting">
Expand Down Expand Up @@ -81,13 +88,6 @@ else
return;
}

if (string.IsNullOrWhiteSpace(model.Password) ||
model.Password != model.ConfirmPassword)
{
invalid = true;
return;
}

// Activate in your DB (invite-only gate)
var ok = await UserService.ActivateUserAsync(token, model.Password);

Expand Down Expand Up @@ -116,9 +116,4 @@ else
}
}

public class PasswordModel
{
public string Password { get; set; } = "";
public string ConfirmPassword { get; set; } = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@
<div class="cc-span2">
<label class="form-label">Admin Password</label>
<InputText type="password" class="form-control cc-input" @bind-Value="Signup.Admin.Password" />
<ValidationMessage For="@(() => Signup.Admin.Password)" />
</div>

<div class="cc-span2">
<label class="form-label">Confirm Password</label>
<InputText type="password" class="form-control cc-input" @bind-Value="Signup.Admin.ConfirmPassword" />
<ValidationMessage For="@(() => Signup.Admin.ConfirmPassword)" />
</div>
</div>
</div>
Expand Down Expand Up @@ -366,6 +373,13 @@
{
errorMessage = "";
successMessage = "";

if (string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName))
{
errorMessage = "First and last name are required.";
return;
}

isSubmitting = true;

try
Expand Down
41 changes: 29 additions & 12 deletions CulinaryCommandApp/Components/Pages/Users/Create.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/users/create"
@rendermode InteractiveServer

@using CulinaryCommand.Models
@using CulinaryCommand.Services.UserContextSpace
@inject IUserService UserService
@inject IUserContextService UserCtx
Expand All @@ -19,6 +20,11 @@ else if (!_allowed)
}
else
{
@if (!string.IsNullOrWhiteSpace(_error))
{
<div class="alert alert-danger">@_error</div>
}

<EditForm Model="_model" OnValidSubmit="Save">
<DataAnnotationsValidator />
<ValidationSummary />
Expand Down Expand Up @@ -54,20 +60,21 @@ else
OnChanged="OnLocationsChanged" />
</div>

<button class="btn btn-success" type="button" @onclick="Save" disabled="@_saving">
<button class="btn btn-success" type="submit" disabled="@_saving">
@(_saving ? "Inviting..." : "Send Invite")
</button>
<button class="btn btn-outline-secondary ms-2" type="button" @onclick="Cancel" disabled="_saving">Cancel</button>
<button class="btn btn-outline-secondary ms-2" type="button" @onclick="Cancel" disabled="@_saving">Cancel</button>
</EditForm>
}

@code {
private bool _hydrated;
private bool _allowed;
private bool _saving;
private bool _saving = false;

private int _companyId;
private int _createdByUserId;
private string? _error;

private InviteUserVm _model = new()
{
Expand Down Expand Up @@ -111,13 +118,26 @@ else
_model.LocationIds = ids ?? new List<int>();
return Task.CompletedTask;
}

private async Task Save()
{
if (_saving) return;
_saving = true;
_error = null;

try
{
if (string.IsNullOrWhiteSpace(_model.Email))
{
_error = "Email is required.";
return;
}

if (_model.LocationIds == null || _model.LocationIds.Count == 0)
{
_error = "Select at least one location.";
return;
}

await UserService.InviteUserAsync(
_model.FirstName,
_model.LastName,
Expand All @@ -130,20 +150,17 @@ else

Nav.NavigateTo("/users");
}
catch (Exception ex)
{
_error = ex.Message;
}
finally
{
_saving = false;
}
}


private void Cancel() => Nav.NavigateTo("/users");

private class InviteUserVm
{
public string FirstName { get; set; } = "";
public string LastName { get; set; } = "";
public string Email { get; set; } = "";
public string Role { get; set; } = "Employee";
public List<int> LocationIds { get; set; } = new();
}
}
Loading
Loading