Skip to content

Commit 7a2009d

Browse files
committed
refactor(price-lists): more refactoring
1 parent 926e9d8 commit 7a2009d

3 files changed

Lines changed: 23 additions & 44 deletions

File tree

src/Filament/Resources/PriceListResource/Pages/CreatePriceList.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,4 @@ protected function getFormActions(): array
4747
$this->getCancelFormAction(),
4848
];
4949
}
50-
51-
/**
52-
* Store current tenant data before submitting
53-
*/
54-
protected function storeCurrentTenantData(): void
55-
{
56-
$formData = $this->form->getState();
57-
$selectedTenant = $formData['selected_tenant'] ?? null;
58-
59-
if ($selectedTenant && config('eclipse-catalogue.tenancy.foreign_key')) {
60-
$currentData = [
61-
'is_active' => $formData['tenant_data'][$selectedTenant]['is_active'] ?? true,
62-
'is_default' => $formData['tenant_data'][$selectedTenant]['is_default'] ?? false,
63-
'is_default_purchase' => $formData['tenant_data'][$selectedTenant]['is_default_purchase'] ?? false,
64-
];
65-
66-
$allTenantData = $formData['all_tenant_data'] ?? [];
67-
$allTenantData[$selectedTenant] = $currentData;
68-
69-
$this->form->fill(['all_tenant_data' => $allTenantData]);
70-
}
71-
}
7250
}

src/Filament/Resources/PriceListResource/Pages/EditPriceList.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,6 @@ protected function getFormActions(): array
100100
];
101101
}
102102

103-
/**
104-
* Store current tenant data before submitting
105-
*/
106-
protected function storeCurrentTenantData(): void
107-
{
108-
$formData = $this->form->getState();
109-
$selectedTenant = $formData['selected_tenant'] ?? null;
110-
111-
if ($selectedTenant && config('eclipse-catalogue.tenancy.foreign_key')) {
112-
$currentData = [
113-
'is_active' => $formData['tenant_data'][$selectedTenant]['is_active'] ?? true,
114-
'is_default' => $formData['tenant_data'][$selectedTenant]['is_default'] ?? false,
115-
'is_default_purchase' => $formData['tenant_data'][$selectedTenant]['is_default_purchase'] ?? false,
116-
];
117-
118-
$allTenantData = $formData['all_tenant_data'] ?? [];
119-
$allTenantData[$selectedTenant] = $currentData;
120-
121-
$this->form->fill(['all_tenant_data' => $allTenantData]);
122-
}
123-
}
124-
125103
protected function resolveRecord($key): Model
126104
{
127105
// Load record without joins to avoid ambiguous column issues

src/Traits/HandlesPriceListTenantData.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77
trait HandlesPriceListTenantData
88
{
9+
/**
10+
* Persist the currently selected tenant's values into the hidden
11+
* all_tenant_data state so switching tenants doesn't lose changes.
12+
*/
13+
protected function storeCurrentTenantData(): void
14+
{
15+
$formData = $this->form->getState();
16+
$selectedTenant = $formData['selected_tenant'] ?? null;
17+
18+
if ($selectedTenant && config('eclipse-catalogue.tenancy.foreign_key')) {
19+
$currentData = [
20+
'is_active' => $formData['tenant_data'][$selectedTenant]['is_active'] ?? true,
21+
'is_default' => $formData['tenant_data'][$selectedTenant]['is_default'] ?? false,
22+
'is_default_purchase' => $formData['tenant_data'][$selectedTenant]['is_default_purchase'] ?? false,
23+
];
24+
25+
$allTenantData = $formData['all_tenant_data'] ?? [];
26+
$allTenantData[$selectedTenant] = $currentData;
27+
28+
$this->form->fill(['all_tenant_data' => $allTenantData]);
29+
}
30+
}
31+
932
/**
1033
* Validate default constraints before saving.
1134
*/

0 commit comments

Comments
 (0)