Hotfix: Company Settings save button not responding

Save button was type=submit, so HTML5 form validation silently blocked
the submit event and nothing happened on click. Switch to type=button
with an explicit click handler. Also replace AutoMapper Map() with
explicit property assignment so EF reliably detects the mutations, and
re-enable the button in showButtonSuccess() after a successful save.

Cherry-picked CompanySettings hunks from dev commit 0b839d0746 as a
targeted production patch off v2026.06.09.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-14 15:04:42 -04:00
parent 7cbae31916
commit c16b2445bc
2 changed files with 16 additions and 10 deletions
@@ -230,11 +230,19 @@ public class CompanySettingsController : Controller
return Json(new { success = false, message = "Company not found." }); return Json(new { success = false, message = "Company not found." });
} }
// Update company properties // Explicit assignment avoids AutoMapper quirks with tracked EF entities
_mapper.Map(dto, company); company.CompanyName = dto.CompanyName.Trim();
company.UpdatedAt = DateTime.UtcNow; company.CompanyCode = string.IsNullOrWhiteSpace(dto.CompanyCode) ? null : dto.CompanyCode.Trim();
company.PrimaryContactName = dto.PrimaryContactName.Trim();
company.PrimaryContactEmail = dto.PrimaryContactEmail.Trim();
company.Phone = string.IsNullOrWhiteSpace(dto.Phone) ? null : dto.Phone.Trim();
company.Address = string.IsNullOrWhiteSpace(dto.Address) ? null : dto.Address.Trim();
company.City = string.IsNullOrWhiteSpace(dto.City) ? null : dto.City.Trim();
company.State = string.IsNullOrWhiteSpace(dto.State) ? null : dto.State.Trim();
company.ZipCode = string.IsNullOrWhiteSpace(dto.ZipCode) ? null : dto.ZipCode.Trim();
company.TimeZone = string.IsNullOrWhiteSpace(dto.TimeZone) ? null : dto.TimeZone.Trim();
company.AccountingMethod = dto.AccountingMethod;
await _unitOfWork.Companies.UpdateAsync(company);
await _unitOfWork.CompleteAsync(); await _unitOfWork.CompleteAsync();
_logger.LogInformation("Company {CompanyId} settings updated by user", companyId); _logger.LogInformation("Company {CompanyId} settings updated by user", companyId);
@@ -312,7 +312,7 @@
</div> </div>
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary" id="btnSaveCompanyInfo"> <button type="button" class="btn btn-primary" id="btnSaveCompanyInfo">
<i class="bi bi-save"></i> Save Changes <i class="bi bi-save"></i> Save Changes
</button> </button>
</div> </div>
@@ -2749,10 +2749,8 @@
} }
}); });
// Company Info Form Submit // Company Info Save
$('#companyInfoForm').on('submit', function (e) { $('#btnSaveCompanyInfo').on('click', function () {
e.preventDefault();
const formData = { const formData = {
CompanyName: $('#companyName').val(), CompanyName: $('#companyName').val(),
CompanyCode: $('#companyCode').val(), CompanyCode: $('#companyCode').val(),
@@ -3192,7 +3190,7 @@
// Button success animation helper // Button success animation helper
function showButtonSuccess(btn, originalHtml, duration = 2000) { function showButtonSuccess(btn, originalHtml, duration = 2000) {
btn.removeClass('btn-primary').addClass('btn-success'); btn.prop('disabled', false).removeClass('btn-primary').addClass('btn-success');
btn.html('<i class="bi bi-check-circle-fill"></i> Saved!'); btn.html('<i class="bi bi-check-circle-fill"></i> Saved!');
setTimeout(function() { setTimeout(function() {
btn.removeClass('btn-success').addClass('btn-primary'); btn.removeClass('btn-success').addClass('btn-primary');