refactor(bottle): streamline data handling in form and enhance placeholder text for clarity
This commit is contained in:
parent
afa7323002
commit
e9e5975e57
@ -8,6 +8,7 @@
|
||||
use App\Traits\WithMediaHandler;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Str;
|
||||
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Column;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Columns\ArrayColumn;
|
||||
@ -38,7 +39,7 @@ public function columns(): array
|
||||
->html(),
|
||||
|
||||
Column::make('Harga Beli', 'cost_price')
|
||||
->label(fn ($row, $column) => currency($row->cost_price, 'Rp'))
|
||||
->label(fn ($row, $column) => Str::mask(currency($row->cost_price, 'Rp'), '*', 2))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
|
||||
@ -74,13 +74,7 @@ public function store()
|
||||
$this->validate();
|
||||
|
||||
DB::transaction(function () {
|
||||
$bottle = Bottle::create([
|
||||
'name' => $this->name,
|
||||
'size' => $this->size,
|
||||
'cost_price' => $this->cost_price,
|
||||
'sale_price' => $this->sale_price,
|
||||
'description' => $this->description,
|
||||
]);
|
||||
$bottle = Bottle::create($this->prepareSavedData());
|
||||
|
||||
$bottle->outlets()->attach($this->outlet_ids);
|
||||
|
||||
@ -93,18 +87,23 @@ public function update()
|
||||
$this->validate();
|
||||
|
||||
DB::transaction(function () {
|
||||
$this->bottle->update([
|
||||
'name' => $this->name,
|
||||
'size' => $this->size,
|
||||
'cost_price' => $this->cost_price,
|
||||
'sale_price' => $this->sale_price,
|
||||
'description' => $this->description,
|
||||
]);
|
||||
$this->bottle->update($this->prepareSavedData());
|
||||
|
||||
$this->bottle->outlets()->attach($this->outlet_ids);
|
||||
$this->bottle->outlets()->sync($this->outlet_ids);
|
||||
|
||||
$this->syncMedia($this->image, $this->bottle, 'image');
|
||||
$this->uploadMedia($this->image, $this->bottle, 'image');
|
||||
});
|
||||
}
|
||||
|
||||
private function prepareSavedData(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'size' => $this->size,
|
||||
'cost_price' => replaceCurrency($this->cost_price),
|
||||
'sale_price' => replaceCurrency($this->sale_price),
|
||||
'description' => $this->description,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
use App\Livewire\Forms\Studio\Catalog\BottleForm;
|
||||
use App\Models\Bottle;
|
||||
use App\Models\Outlet;
|
||||
use App\Traits\WithAuthorization;
|
||||
use App\Traits\WithOutletSelector;
|
||||
use App\Traits\WithToast;
|
||||
use App\Traits\WithUpdatedData;
|
||||
@ -14,7 +15,7 @@
|
||||
#[Title('Ubah Botol')]
|
||||
class Edit extends Component
|
||||
{
|
||||
use WithOutletSelector, WithToast, WithUpdatedData;
|
||||
use WithAuthorization, WithOutletSelector, WithToast, WithUpdatedData;
|
||||
|
||||
public BottleForm $form;
|
||||
|
||||
|
||||
@ -20,15 +20,15 @@
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<flux:field>
|
||||
<flux:label>Nama <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input placeholder="Masukkan nama produk"
|
||||
<flux:input placeholder="Contoh: Le Labo"
|
||||
wire:model.live.debounce.500ms="form.name" autofocus autocomplete="off" />
|
||||
<flux:error name="form.name" />
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>Ukuran <span class="text-red-500 ms-1">*</span></flux:label>
|
||||
<flux:input placeholder="Masukkan ukuran"
|
||||
wire:model.live.debounce.500ms="form.size" autocomplete="off" />
|
||||
<flux:input placeholder="Contoh: 35" wire:model.live.debounce.500ms="form.size"
|
||||
autocomplete="off" />
|
||||
<flux:error name="form.size" />
|
||||
</flux:field>
|
||||
|
||||
@ -56,8 +56,8 @@
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<flux:editor label="Deskripsi" wire:model="form.description"
|
||||
placeholder="Masukkan deskripsi" auotocomplete="off"
|
||||
class="**:data-[slot=content]:min-h-[100px]!" />
|
||||
placeholder="Botol Le Labo memiliki desain yang minimalis dan elegan, khas gaya modern klasik"
|
||||
auotocomplete="off" class="**:data-[slot=content]:min-h-[100px]!" />
|
||||
</div>
|
||||
</div>
|
||||
</flux:card>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user