shoc-backend/SeaHavenIndustries/Components/Pages/UserSetting/Index.razor
2024-09-28 14:58:36 -04:00

359 lines
No EOL
20 KiB
Text

@page "/usersettings"
<Header pagename="Users " icon='<i class="material-icons-round opacity-10">person</i>'></Header>
<div class="">
<div class="d-flex justify-content-between mb-3">
</div>
<div class="p-0 position-relative mx-4 z-index-2">
<div class="tab-content card-background-transparent" id="v-pills-tabContent">
<div class="tab-pane fade show position-relative active" id="cam1" role="tabpanel" aria-labelledby="cam1" loading="lazy">
<div class="row">
<div class="col-md-3 mx-0 px-0">
<div class="nav card flex-column cardbg nav-pills me-3 py-3 my-0" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<button class="nav-link h-navlinks py-2 my-0 active" id="v-pills-home-tab" data-bs-toggle="pill" data-bs-target="#v-pills-home" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="true" tabindex="-1">
<a class="nav-link1 d-flex align-items-center px-0 mx-0 ">
<span class="text-sm">Personal Information</span>
</a>
</button>
<button class="nav-link h-navlinks py-2 my-0" id="v-pills-profile-tab" data-bs-toggle="pill" data-bs-target="#v-pills-profile" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="true" tabindex="-1">
<a class="nav-link1 d-flex align-items-center px-0 mx-0">
<span class="text-sm">Update Password</span>
</a>
</button>
</div>
</div>
<div class="col-md-9">
<div class="tab-content">
<div class="tab-pane fade active show" id="v-pills-home" role="tabpanel">
@if (step == 0)
{
<div class="card p-3 cardbg" id="Div5">
<div class="col-md-12 d-flex justify-content-between">
<div class="col-md-6 d-flex">
<i class="material-icons text-xxl me-2">person</i>
<h6>Profile</h6>
</div>
<div class="col-md-6 text-end">
<a href="javascript:void(0)">
<span class="material-icons material-symbols-outlined text-warning" @onclick="()=> Changestep1(1)">
drive_file_rename_outline
</span>
</a>
</div>
</div>
<div class="row">
@* <div class="col-md-3 col-lg-3">
@if(model.UserImage == null)
{
<img src="../../assets/img/team-3.jpg" alt="img-blur-shadow" class="img-fluid shadow border-radius-lg" style="height: 156px;width: 100%;">
}
else
{
<img src="@model.UserImage" alt="img-blur-shadow" class="img-fluid shadow border-radius-lg" style="height: 156px;width: 100%;">
}
<div class="text-center mt-1">
<h6 class="text-sm">@model.FirstName</h6>
</div>
</div> *@
<div class="col-md-9 col-lg-9">
<div class="row">
<div class="col-2">
<label class="form-label">Name :</label>
</div>
<div class="col-2">
<label class="form-label"> </label>
</div>
<div class="col-4">
<label class="form-label">@model.FirstName</label>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="form-label">Email :</label>
</div>
<div class="col-2">
<label class="form-label"> </label>
</div>
<div class="col-4">
<label class="form-label">@model.Email</label>
</div>
</div>
<div class="row">
<div class="col-2">
<label class="form-label">Phone # :</label>
</div>
<div class="col-2">
<label class="form-label"> </label>
</div>
<div class="col-4">
<label class="form-label">@model.Contact</label>
</div>
</div>
</div>
</div>
</div>
}
@if (step == 1)
{
<div class="card p-3 cardbg" id="Div6">
<div class="row justify-content-start">
<div class="d-flex">
<i class="material-icons pe-2 pt-1 cursor-pointer" @onclick="() => Changestep1(0)">reply</i> <h6>Edit Profile</h6>
</div>
</div>
<div class="row">
<form @onsubmit="UpdateData" enctype="multipart/form-data">
<input type="hidden" class="form-control" asp-for="Id">
<div class="col-12 ">
<div class="col-md-12">
<label class="form-label">First Name</label>
<div class="input-group input-group-outline mb-1 ">
<input type="text" class="form-control" name="FirstName" aria-label="FirstName" @bind="model.FirstName">
</div>
</div>
<div class="col-md-12">
<label class="form-label">Last Name</label>
<div class="input-group input-group-outline mb-1 ">
<input type="text" class="form-control" name="LastName" aria-label="FirstName" @bind="model.LastName">
</div>
</div>
<div class="col-md-12">
<label class="form-label">Email</label>
<div class="input-group input-group-outline mb-1">
<input type="email" class="form-control" readonly disabled name="Email" @bind="model.Email">
</div>
</div>
<div class="col-md-12">
<label class="form-label">Phone #</label>
<div class="input-group input-group-outline mb-1">
<input type="text" class="form-control" name="PhoneNumber" @oninput="FormatPhoneNumber" aria-label="PhoneNumber" @bind="model.Contact">
</div>
</div>
@* <div class="col-md-12">
<label class="form-label">Location</label>
<div class="input-group input-group-outline mb-1">
<input type="text" class="form-control" name="Address" aria-label="Address" @bind="model.Locations">
</div>
</div> *@
</div>
@* <div class="row">
<div class="col-md-12">
<label class="form-label">Upload Profile Image</label>
<div class="input-group input-group-outline d-flex ">
<InputFile type="file" class="input-active form-control" id="file-upload" OnChange="@ProfileUpload" />
</div>
</div>
<div class="col-md-6 text-end mt-3">
</div>
</div> *@
<div class="d-flex mt-3" style="justify-content:end; align-items: center;">
<div>
<button type="submit" class="btn bg-gradient-info btn-sm mb-0">
Save Changes
</button>
</div>
</div>
</form>
</div>
</div>
}
</div>
<div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
<div class="card p-2 cardbg">
<div class="card-body">
<div class="row justify-content-start">
<div class="d-flex">
<span class="material-icons material-symbols-outlined me-2">
lock
</span>
<h6>Update Password</h6>
</div>
</div>
<div class="row">
<div class="col-12 d-flex align-items-center">
<input type="hidden" asp-for="Id" name="uid">
<input type="hidden" class="form-control" name="Email">
<div class="col-3 my-2">
<p class="mt-2">Current password</p>
</div>
<div class="col-md-9">
<div class="input-group input-group-outline ">
<input type="password" class="form-control" name="oldpassword" aria-label="Password" @bind="changePasswords.Currentpassword">
</div>
</div>
</div>
<div class="col-12 d-flex align-items-center">
<div class="col-3 ">
<p class="mt-2">New Password</p>
</div>
<div class="col-md-9">
<div class="input-group input-group-outline my-1">
<input type="password" class="form-control" name="newpassword" aria-label="Password" @bind="changePasswords.Newpassword">
</div>
</div>
</div>
<div class="col-12 d-flex align-items-center">
<div class="col-3 ">
<p class="mt-2">
Confirm New Password
</p>
</div>
<div class="col-md-9">
<div class="input-group input-group-outline ">
<input type="password" class="form-control" name="confirmnewpassword" aria-label="Password" @bind="changePasswords.Confirmpassword">
</div>
</div>
</div>
<div class="d-flex mt-3" style="justify-content:end; align-items: center;">
<div>
<div class="d-flex mt-3" style="justify-content:end; align-items: center;">
<div>
<button type="submit" class="btn bg-gradient-info btn-sm mb-0" @onclick="updatepassword">
Save Changes
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@using SeaHavenIndustries.Data.IRepository;
@inject ISettingsRepository _service;
@using Microsoft.JSInterop
@using global::Data.SeaHavenIndustries
@inject IJSRuntime JSRuntime
@inject NavigationManager Navigation
@inject ChangeStepService StepService
@implements IDisposable
@code {
private int step = 0;
private int steptab = 0;
private async Task Changestep1(int val)
{
step = val;
await InvokeAsync(StateHasChanged);
}
private ApplicationUser model = new();
private IEnumerable<ApplicationUser>? modelList { get; set; }
private Category category = new();
private List<Category>? categories { get; set; }
private async Task ChangeStep(int newStep)
{
steptab = newStep;
await InvokeAsync(StateHasChanged);
}
private IBrowserFile file;
private void ProfileUpload(InputFileChangeEventArgs e)
{
var imageFiles = e.File;
file = imageFiles;
}
protected override void OnInitialized()
{
StepService.OnStateChange += StateHasChanged;
}
public void Dispose()
{
StepService.OnStateChange -= StateHasChanged;
}
protected override async Task OnParametersSetAsync()
{
model = await _service.GetCurrentUserInfo();
}
protected async Task UpdateData()
{
var res = await _service.UpdateUser(model, file);
if (res == "success")
{
await ShowSweetAlert("Sucessfully Saved Data", "success");
model = await _service.GetCurrentUserInfo();
}
else
{
await ShowSweetAlert(res, "error");
}
}
private void FormatPhoneNumber(ChangeEventArgs e)
{
string input = e.Value?.ToString();
string numericOnly = new string(input?.Where(c => char.IsDigit(c)).ToArray());
if (numericOnly.Length >= 3)
{
string formattedNumber = $"({numericOnly.Substring(0, 3)}";
if (numericOnly.Length >= 6)
{
formattedNumber += $") {numericOnly.Substring(3, 3)}";
if (numericOnly.Length >= 10)
{
formattedNumber += $"-{numericOnly.Substring(6, 4)}";
}
}
model.Contact = formattedNumber;
}
else
{
model.Contact = numericOnly;
}
}
protected ChangePasswords changePasswords = new();
protected async Task updatepassword()
{
var res = await _service.Changepassword(changePasswords);
if (res == "success")
{
await ShowSweetAlert("Password Updated Sucessfully", "success");
}
else if (res == "notmatched")
{
await ShowSweetAlert("New Password and Confirm Password are not Match", "error");
}
else
{
await ShowSweetAlert(res, "error");
}
}
private async Task ShowSweetAlert(string title, string icon)
{
// Display a SweetAlert dialog
await JSRuntime.InvokeVoidAsync("Swal.fire", new
{
toast = true,
showConfirmButton = false,
timer = 3000,
title = title,
icon = icon,
position = "top-end"
});
await JSRuntime.InvokeVoidAsync("closemodal");
}
}