intial ticket fix partial delete fix
This commit is contained in:
@@ -199,6 +199,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveCategory(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('categoryForm', ['company_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'categoryForm.company_id' => ['nullable', 'integer'],
|
||||
'categoryForm.name' => ['required', 'string', 'max:120'],
|
||||
@@ -241,6 +243,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveTeam(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('teamForm', ['company_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'teamForm.company_id' => ['nullable', 'integer'],
|
||||
'teamForm.name' => ['required', 'string', 'max:120'],
|
||||
@@ -283,6 +287,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveProject(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('projectForm', ['company_id', 'team_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'projectForm.company_id' => ['nullable', 'integer'],
|
||||
'projectForm.team_id' => ['nullable', 'integer', 'exists:helpdesk_teams,id'],
|
||||
@@ -326,6 +332,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveBoard(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('boardForm', ['owner_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'boardForm.name' => ['required', 'string', 'max:160'],
|
||||
'boardForm.slug' => ['nullable', 'string', 'max:180'],
|
||||
@@ -391,6 +399,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveRepository(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('repositoryForm', ['company_id', 'project_id', 'webhook_secret']);
|
||||
|
||||
$data = $this->validate([
|
||||
'repositoryForm.company_id' => ['nullable', 'integer'],
|
||||
'repositoryForm.project_id' => ['nullable', 'integer', 'exists:helpdesk_projects,id'],
|
||||
@@ -427,6 +437,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveWorkflowTemplate(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('workflowForm', ['text_body', 'cc', 'bcc']);
|
||||
|
||||
$data = $this->validate([
|
||||
'workflowForm.name' => ['required', 'string', 'max:160'],
|
||||
'workflowForm.event' => ['required', 'string', 'max:80'],
|
||||
@@ -463,6 +475,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveCannedResponse(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('cannedForm', ['company_id', 'category_id', 'team_id', 'subject']);
|
||||
|
||||
$data = $this->validate([
|
||||
'cannedForm.company_id' => ['nullable', 'integer'],
|
||||
'cannedForm.category_id' => ['nullable', 'integer', 'exists:helpdesk_categories,id'],
|
||||
@@ -500,6 +514,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveSlaPolicy(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('slaForm', ['company_id', 'priority_id', 'category_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'slaForm.company_id' => ['nullable', 'integer'],
|
||||
'slaForm.priority_id' => ['nullable', 'integer', 'exists:helpdesk_priorities,id'],
|
||||
@@ -540,6 +556,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveAutomationRule(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('automationForm', ['company_id', 'match_sender', 'match_subject', 'match_mailbox', 'match_category_id', 'set_priority_id', 'set_category_id', 'set_team_id', 'set_project_id', 'set_status_id', 'set_agent_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'automationForm.company_id' => ['nullable', 'integer'],
|
||||
'automationForm.name' => ['required', 'string', 'max:160'],
|
||||
@@ -582,6 +600,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveProduct(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('productForm', ['company_id', 'version', 'release_channel', 'description']);
|
||||
|
||||
$data = $this->validate([
|
||||
'productForm.company_id' => ['nullable', 'integer'],
|
||||
'productForm.name' => ['required', 'string', 'max:160'],
|
||||
@@ -617,6 +637,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveTag(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('tagForm', ['company_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'tagForm.company_id' => ['nullable', 'integer'],
|
||||
'tagForm.name' => ['required', 'string', 'max:80'],
|
||||
@@ -648,6 +670,8 @@ final class SettingsManager extends Component
|
||||
|
||||
public function saveChecklistTemplate(): void
|
||||
{
|
||||
$this->normalizeNullableFormValues('checklistTemplateForm', ['company_id', 'category_id', 'project_id']);
|
||||
|
||||
$data = $this->validate([
|
||||
'checklistTemplateForm.company_id' => ['nullable', 'integer'],
|
||||
'checklistTemplateForm.category_id' => ['nullable', 'integer', 'exists:helpdesk_categories,id'],
|
||||
@@ -694,8 +718,10 @@ final class SettingsManager extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$this->normalizeNullableScalar('default_helpdesk_company_id');
|
||||
|
||||
$this->validate([
|
||||
'default_helpdesk_company_id' => ['nullable'],
|
||||
'default_helpdesk_company_id' => ['nullable', 'integer', 'exists:companies,id'],
|
||||
]);
|
||||
|
||||
$companyId = filled($this->default_helpdesk_company_id)
|
||||
@@ -796,6 +822,35 @@ final class SettingsManager extends Component
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert browser select empty strings into null before Livewire validation.
|
||||
*
|
||||
* Flux/select controls submit optional values as empty strings. Laravel's
|
||||
* nullable integer and exists rules expect a real null, so normalising here
|
||||
* keeps every settings CRUD form usable from the browser.
|
||||
*
|
||||
* @param array<int, string> $keys
|
||||
*/
|
||||
private function normalizeNullableFormValues(string $formProperty, array $keys): void
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if (! array_key_exists($key, $this->{$formProperty})) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (blank($this->{$formProperty}[$key])) {
|
||||
$this->{$formProperty}[$key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeNullableScalar(string $property): void
|
||||
{
|
||||
if (blank($this->{$property})) {
|
||||
$this->{$property} = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove is_default before save when the database has not been migrated yet.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user