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