Profile save/load works
Still need to add skills, but #2 is getting there...
This commit is contained in:
@@ -25,7 +25,7 @@ else
|
||||
@code {
|
||||
|
||||
bool retrievingProfile = true;
|
||||
JobsJobsJobs.Shared.Profile? profile = null;
|
||||
Profile? profile = null;
|
||||
string? errorMessage = null;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
|
||||
89
src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor
Normal file
89
src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor
Normal file
@@ -0,0 +1,89 @@
|
||||
@page "/citizen/profile"
|
||||
|
||||
<h3>Employment Profile</h3>
|
||||
|
||||
@if (ErrorMessage != "")
|
||||
{
|
||||
<p>@ErrorMessage</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditForm Model="@ProfileForm" OnValidSubmit="@SaveProfile">
|
||||
<DataAnnotationsValidator />
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="seeking" class="form-check-input" @bind-Value="@ProfileForm.IsSeekingEmployment" />
|
||||
<label for="seeking" class="form-check-label">I am currently seeking employment</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col col-xs-12 col-sm-6 col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="continentId" class="jjj-required">Continent</label>
|
||||
<InputSelect id="continentId" @bind-Value="@ProfileForm.ContinentId" class="form-control">
|
||||
<option>– Select –</option>
|
||||
@foreach (var (id, name) in Continents)
|
||||
{
|
||||
<option value="@id">@name</option>
|
||||
}
|
||||
</InputSelect>
|
||||
<ValidationMessage For="@(() => ProfileForm.ContinentId)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-xs-12 col-sm-6 col-md-8">
|
||||
<div class="form-group">
|
||||
<label for="region" class="jjj-required">Region</label>
|
||||
<InputText id="region" @bind-Value="@ProfileForm.Region" class="form-control" />
|
||||
<ValidationMessage For="@(() => ProfileForm.Region)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="bio" class="jjj-required">Professional Biography</label>
|
||||
<MarkdownEditor Id="bio" @bind-Text="@ProfileForm.Biography" />
|
||||
<ValidationMessage For="@(() => ProfileForm.Biography)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col col-xs-12 col-sm-12 offset-md-2 col-md-4">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="isRemote" class="form-check-input" @bind-Value="@ProfileForm.RemoteWork" />
|
||||
<label for="isRemote" class="form-check-label">I am looking for remote work</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-xs-12 col-sm-12 col-md-4">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="isFull" class="form-check-input" @bind-Value="@ProfileForm.FullTime" />
|
||||
<label for="isFull" class="form-check-label">I am looking for full-time work</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<label for="experience">Experience</label>
|
||||
<MarkdownEditor Id="experience" @bind-Text="@ProfileForm.Experience" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="isPublic" class="form-check-input" @bind-Value="@ProfileForm.IsPublic" />
|
||||
<label for="isPublic" class="form-check-label">
|
||||
Allow my profile to be searched publicly (outside NA Social)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<br>
|
||||
<button type="submit" class="btn btn-outline-primary">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
84
src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor.cs
Normal file
84
src/JobsJobsJobs/Client/Pages/Citizen/EditProfile.razor.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using JobsJobsJobs.Shared;
|
||||
using JobsJobsJobs.Shared.Api;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JobsJobsJobs.Client.Pages.Citizen
|
||||
{
|
||||
/// <summary>
|
||||
/// Profile edit page (called EditProfile so as not to create naming conflicts)
|
||||
/// </summary>
|
||||
public partial class EditProfile : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The form for this page
|
||||
/// </summary>
|
||||
private ProfileForm ProfileForm { get; set; } = new ProfileForm();
|
||||
|
||||
/// <summary>
|
||||
/// All continents
|
||||
/// </summary>
|
||||
private IEnumerable<Continent> Continents { get; set; } = Enumerable.Empty<Continent>();
|
||||
|
||||
/// <summary>
|
||||
/// Error message from API access
|
||||
/// </summary>
|
||||
private string ErrorMessage { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// HTTP client instance to use for API access
|
||||
/// </summary>
|
||||
[Inject]
|
||||
private HttpClient Http { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Application state
|
||||
/// </summary>
|
||||
[Inject]
|
||||
private AppState State { get; set; } = default!;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
ServerApi.SetJwt(Http, State);
|
||||
var continentResult = await ServerApi.AllContinents(Http, State);
|
||||
if (continentResult.IsOk)
|
||||
{
|
||||
Continents = continentResult.Ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = continentResult.Error;
|
||||
}
|
||||
|
||||
var result = await ServerApi.RetrieveProfile(Http, State);
|
||||
if (result.IsOk)
|
||||
{
|
||||
System.Console.WriteLine($"Result is null? {result.Ok == null}");
|
||||
ProfileForm = (result.Ok == null) ? new ProfileForm() : ProfileForm.FromProfile(result.Ok);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = result.Error;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveProfile()
|
||||
{
|
||||
var res = await Http.PostAsJsonAsync("/api/profile/save", ProfileForm);
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
// TODO: success notification
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: probably not the best way to handle this...
|
||||
ErrorMessage = await res.Content.ReadAsStringAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
@page "/citizen/profile"
|
||||
@using JobsJobsJobs.Client.ViewModels
|
||||
@inject HttpClient http
|
||||
@inject AppState state
|
||||
|
||||
<h3>Employment Profile</h3>
|
||||
|
||||
@if (errorMessage != "")
|
||||
{
|
||||
<p>@errorMessage</p>
|
||||
}
|
||||
else if (profileForm != null)
|
||||
{
|
||||
<EditForm Model="@profileForm" OnValidSubmit="@SaveProfile">
|
||||
<DataAnnotationsValidator />
|
||||
<div class="form-row">
|
||||
<div class="col col-xs-12 col-sm-12 col-md-4">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="seeking" class="form-check-input" @bind-Value="@profileForm.IsSeekingEmployment" />
|
||||
<label for="seeking" class="form-check-label">I am currently seeking employment</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-xs-12 col-sm-12 col-md-8">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="isPublic" class="form-check-input" @bind-Value="@profileForm.IsPublic" />
|
||||
<label for="isPublic" class="form-check-label">
|
||||
Allow my profile to be searched publicly (outside NA Social)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col col-xs-12 col-sm-12 col-md-4">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="isRemote" class="form-check-input" @bind-Value="@profileForm.RemoteWork" />
|
||||
<label for="isRemote" class="form-check-label">I am looking for remote work</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-xs-12 col-sm-12 col-md-8">
|
||||
<div class="form-check">
|
||||
<InputCheckbox id="isFull" class="form-check-input" @bind-Value="@profileForm.FullTime" />
|
||||
<label for="isFull" class="form-check-label">I am looking for full-time work</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col col-xs-12 col-sm-6 col-md-4">
|
||||
<div class="form-group">
|
||||
<label for="continentId">Continent</label>
|
||||
<InputSelect id="continentId" @bind-Value="@profileForm.ContinentId" class="form-control">
|
||||
<option>– Select –</option>
|
||||
@foreach (var (id, name) in continents)
|
||||
{
|
||||
<option value="@id">@name</option>
|
||||
}
|
||||
</InputSelect>
|
||||
<ValidationMessage For="@(() => profileForm.ContinentId)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col col-xs-12 col-sm-6 col-md-8">
|
||||
<div class="form-group">
|
||||
<label for="region">Region</label>
|
||||
<InputText id="region" @bind-Value="@profileForm.Region" class="form-control" />
|
||||
<ValidationMessage For="@(() => profileForm.Region)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="bio">Professional Biography</label>
|
||||
<MarkdownEditor Id="bio" @bind-Text="@profileForm.Biography" />
|
||||
<ValidationMessage For="@(() => profileForm.Biography)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<label for="experience">Experience</label>
|
||||
<MarkdownEditor Id="experience" @bind-Text="@profileForm.Experience" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<br>
|
||||
<button type="submit" class="btn btn-outline-primary">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
|
||||
@code {
|
||||
|
||||
public JobsJobsJobs.Shared.Profile? profile = null;
|
||||
|
||||
public ProfileForm? profileForm = null;
|
||||
|
||||
private IEnumerable<Continent> continents = Enumerable.Empty<Continent>();
|
||||
|
||||
public string errorMessage = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var continentResult = await ServerApi.AllContinents(http, state);
|
||||
if (continentResult.IsOk)
|
||||
{
|
||||
continents = continentResult.Ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = continentResult.Error;
|
||||
}
|
||||
|
||||
var result = await ServerApi.RetrieveProfile(http, state);
|
||||
if (result.IsOk)
|
||||
{
|
||||
profile = result.Ok;
|
||||
profileForm = (profile == null) ? new ProfileForm() : ProfileForm.FromProfile(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = result.Error;
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveProfile()
|
||||
{
|
||||
// TODO: save profile
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user