Skills now saved / returned
Edging closer to #2 completion; need to finish styles, create display page, and put some interesting stuff on the dashboard
This commit is contained in:
@@ -2,88 +2,115 @@
|
||||
|
||||
<h3>Employment Profile</h3>
|
||||
|
||||
@if (ErrorMessage != "")
|
||||
@if (AllLoaded)
|
||||
{
|
||||
<p>@ErrorMessage</p>
|
||||
@if (ErrorMessages.Count > 0)
|
||||
{
|
||||
<p><strong>Error</strong></p>
|
||||
@foreach (var msg in ErrorMessages)
|
||||
{
|
||||
<p>@msg</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"
|
||||
placeholder="Country, state, geographic area, etc." />
|
||||
<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>
|
||||
<hr>
|
||||
<h4>
|
||||
Skills
|
||||
<button type="button" class="btn btn-outline-primary" @onclick="@AddNewSkill">Add a Skill</button>
|
||||
</h4>
|
||||
@foreach (var skill in ProfileForm.Skills)
|
||||
{
|
||||
<SkillEdit Skill="@skill" OnRemove="@RemoveSkill" />
|
||||
}
|
||||
<hr>
|
||||
<h4>Experience</h4>
|
||||
<p>
|
||||
This application does not have a place to individually list your chronological job history; however, you can
|
||||
use this area to list prior jobs, their dates, and anything else you want to include that’s not already a
|
||||
part of your Professional Biography above.
|
||||
</p>
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<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>
|
||||
}
|
||||
}
|
||||
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>
|
||||
<p>Loading your profile...</p>
|
||||
}
|
||||
|
||||
@@ -14,6 +14,16 @@ namespace JobsJobsJobs.Client.Pages.Citizen
|
||||
/// </summary>
|
||||
public partial class EditProfile : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Counter for IDs when "Add a Skill" button is clicked
|
||||
/// </summary>
|
||||
private int _newSkillCounter = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A flag that indicates all the required API calls have completed, and the form is ready to be displayed
|
||||
/// </summary>
|
||||
private bool AllLoaded { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The form for this page
|
||||
/// </summary>
|
||||
@@ -25,9 +35,9 @@ namespace JobsJobsJobs.Client.Pages.Citizen
|
||||
private IEnumerable<Continent> Continents { get; set; } = Enumerable.Empty<Continent>();
|
||||
|
||||
/// <summary>
|
||||
/// Error message from API access
|
||||
/// Error messages from API access
|
||||
/// </summary>
|
||||
private string ErrorMessage { get; set; } = "";
|
||||
private IList<string> ErrorMessages { get; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// HTTP client instance to use for API access
|
||||
@@ -44,30 +54,77 @@ namespace JobsJobsJobs.Client.Pages.Citizen
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
ServerApi.SetJwt(Http, State);
|
||||
var continentResult = await ServerApi.AllContinents(Http, State);
|
||||
if (continentResult.IsOk)
|
||||
var continentTask = ServerApi.RetrieveMany<Continent>(Http, "continent/all");
|
||||
var profileTask = ServerApi.RetrieveProfile(Http, State);
|
||||
var skillTask = ServerApi.RetrieveMany<Skill>(Http, "profile/skills");
|
||||
|
||||
await Task.WhenAll(continentTask, profileTask, skillTask);
|
||||
|
||||
if (continentTask.Result.IsOk)
|
||||
{
|
||||
Continents = continentResult.Ok;
|
||||
Continents = continentTask.Result.Ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = continentResult.Error;
|
||||
ErrorMessages.Add(continentTask.Result.Error);
|
||||
}
|
||||
|
||||
var result = await ServerApi.RetrieveProfile(Http, State);
|
||||
if (result.IsOk)
|
||||
if (profileTask.Result.IsOk)
|
||||
{
|
||||
System.Console.WriteLine($"Result is null? {result.Ok == null}");
|
||||
ProfileForm = (result.Ok == null) ? new ProfileForm() : ProfileForm.FromProfile(result.Ok);
|
||||
ProfileForm = (profileTask.Result.Ok == null)
|
||||
? new ProfileForm()
|
||||
: ProfileForm.FromProfile(profileTask.Result.Ok);
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = result.Error;
|
||||
ErrorMessages.Add(profileTask.Result.Error);
|
||||
}
|
||||
|
||||
if (skillTask.Result.IsOk)
|
||||
{
|
||||
foreach (var skill in skillTask.Result.Ok)
|
||||
{
|
||||
ProfileForm.Skills.Add(new SkillForm
|
||||
{
|
||||
Id = skill.Id.ToString(),
|
||||
Description = skill.Description,
|
||||
Notes = skill.Notes ?? ""
|
||||
});
|
||||
}
|
||||
if (ProfileForm.Skills.Count == 0) AddNewSkill();
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessages.Add(skillTask.Result.Error);
|
||||
}
|
||||
|
||||
AllLoaded = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new skill to the form
|
||||
/// </summary>
|
||||
private void AddNewSkill() =>
|
||||
ProfileForm.Skills.Add(new SkillForm { Id = $"new{_newSkillCounter++}" });
|
||||
|
||||
/// <summary>
|
||||
/// Remove the skill for the given ID
|
||||
/// </summary>
|
||||
/// <param name="skillId">The ID of the skill to remove</param>
|
||||
private void RemoveSkill(string skillId) =>
|
||||
ProfileForm.Skills.Remove(ProfileForm.Skills.First(s => s.Id == skillId));
|
||||
|
||||
/// <summary>
|
||||
/// Save changes to the current profile
|
||||
/// </summary>
|
||||
public async Task SaveProfile()
|
||||
{
|
||||
// Remove any skills left blank
|
||||
var blankSkills = ProfileForm.Skills
|
||||
.Where(s => string.IsNullOrEmpty(s.Description) && string.IsNullOrEmpty(s.Notes))
|
||||
.ToList();
|
||||
foreach (var blankSkill in blankSkills) ProfileForm.Skills.Remove(blankSkill);
|
||||
|
||||
var res = await Http.PostAsJsonAsync("/api/profile/save", ProfileForm);
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
@@ -76,7 +133,7 @@ namespace JobsJobsJobs.Client.Pages.Citizen
|
||||
else
|
||||
{
|
||||
// TODO: probably not the best way to handle this...
|
||||
ErrorMessage = await res.Content.ReadAsStringAsync();
|
||||
ErrorMessages.Add(await res.Content.ReadAsStringAsync());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user