Skip to content

Commit

Permalink
Fix: country flag on customer address (#270)
Browse files Browse the repository at this point in the history
* Update Enum with custom traits to use static methods call

* fix: Flag on customer profile

* fix code formatting

---------

Co-authored-by: mckenziearts <[email protected]>
  • Loading branch information
mckenziearts and mckenziearts authored Jul 29, 2024
1 parent 0d77d9e commit b90f387
Show file tree
Hide file tree
Showing 98 changed files with 261 additions and 142 deletions.
2 changes: 1 addition & 1 deletion packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"resolve-url-loader": "^2.3.1",
"shiki": "^1.3.0",
"sortablejs": "^1.15.0",
"tailwindcss": "^3.4.1"
"tailwindcss": "^3.4.7"
},
"dependencies": {
"treeselectjs": "^0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/public/shopper.css

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
</span>
</div>
<h4 class="mt-1 block text-sm font-medium text-gray-900 dark:text-white">
{{ $address->last_name . ' ' . $address->first_name }}
{{ $address->full_name }}
</h4>
<div class="mt-1 text-sm leading-5">
<p class="text-gray-500 dark:text-gray-400">
{{ $address->street_address }}, {{ $address->city }}
{{ $address->street_address }}
</p>
<div class="truncate text-sm text-gray-500 dark:text-gray-400">
<span>{{ $address->phone_number }}</span>
<br />
<span>{{ $address->zipcode }}</span>
,
<span>{{ $address->country->name }}</span>
<span class="inline-flex h-6 w-6 rounded-full">{{ $address->country->svg_flag }}</span>
<div class="flex flex-col space-y-0.5 truncate text-sm text-gray-500 dark:text-gray-400">
<span>{{ $address->postal_code }}, {{ $address->city }}</span>
<span class="inline-flex items-center gap-2 shrink-0">
<span>{{ $address->country->name }}</span>
<img src="{{ $address->country->svg_flag }}" class="size-5 rounded-full object-center object-cover" alt="Country flag">
</span>
@if($address->phone_number)
<span>{{ $address->phone_number }}</span>
@endif
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Console/UserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function createUser(): void
$model = config('auth.providers.users.model', User::class);

try {
$user = tap((new $model())->forceFill($userData))->save(); // @phpstan-ignore-line
$user = tap((new $model)->forceFill($userData))->save(); // @phpstan-ignore-line

$user->assignRole(config('shopper.core.users.admin_role'));
} catch (Exception | QueryException $e) {
Expand Down
8 changes: 8 additions & 0 deletions packages/admin/src/Enum/FeatureState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace Shopper\Enum;

use Shopper\Core\Traits\HasEnumStaticMethods;

/**
* @method static string Enabled()
* @method static string Disabled()
*/
enum FeatureState: string
{
use HasEnumStaticMethods;

case Enabled = 'enabled';

case Disabled = 'disabled';
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Components/Account/Devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function render(): View

protected function createAgent($session): Agent
{
return tap(new Agent(), function ($agent) use ($session): void {
return tap(new Agent, function ($agent) use ($session): void {
$agent->setUserAgent($session->user_agent);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new ProductRepository())
(new ProductRepository)
->makeModel()
->where('parent_id', $this->product->id)
->newQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new UserRepository())
(new UserRepository)
->with('roles')
->makeModel()
->whereHas('roles', function (Builder $query): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Components/SlideOverPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function openPanel($component, $arguments = [], $panelAttributes = []): v
$id = md5($component . serialize($arguments));

$arguments = collect($arguments)
->merge($this->resolveComponentProps($arguments, new $componentClass()))
->merge($this->resolveComponentProps($arguments, new $componentClass))
->all();

$this->components[$id] = [
Expand Down Expand Up @@ -93,7 +93,7 @@ protected function resolveParameter($attributes, $parameterName, $parameterClass
$instance = app()->make($parameterClassName);

if (! $model = $instance->resolveRouteBinding($parameterValue)) {
throw (new ModelNotFoundException())->setModel(get_class($instance), [$parameterValue]);
throw (new ModelNotFoundException)->setModel(get_class($instance), [$parameterValue]);
}

return $model;
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Modals/CollectionProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CollectionProductsList extends ModalComponent

public function mount(int $collectionId, array $exceptProductIds = []): void
{
$this->collection = (new CollectionRepository())->getById($collectionId);
$this->collection = (new CollectionRepository)->getById($collectionId);
$this->exceptProductIds = $exceptProductIds;
}

Expand All @@ -36,7 +36,7 @@ public static function modalMaxWidth(): string
#[Computed]
public function products(): Collection
{
return (new ProductRepository())
return (new ProductRepository)
->where('name', '%' . $this->search . '%', 'like')
->whereNull('parent_id')
->get(['name', 'price_amount', 'id'])
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Modals/RelatedProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RelatedProductsList extends ModalComponent

public function mount(int $productId, array $ids = []): void
{
$this->product = (new ProductRepository())->getById($productId);
$this->product = (new ProductRepository)->getById($productId);
$this->exceptProductIds = $ids;
}

Expand All @@ -32,7 +32,7 @@ public static function modalMaxWidth(): string

public function getProductsProperty()
{
return (new ProductRepository())
return (new ProductRepository)
->where('name', '%' . $this->search . '%', 'like')
->whereNull('parent_id')
->get(['name', 'price_amount', 'id'])
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Pages/Brand/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function mount(): void
public function table(Table $table): Table
{
return $table
->query((new BrandRepository())->makeModel()->newQuery())
->query((new BrandRepository)->makeModel()->newQuery())
->columns([
Tables\Columns\SpatieMediaLibraryImageColumn::make('Logo')
->collection(config('shopper.core.storage.thumbnail_collection'))
Expand Down Expand Up @@ -129,7 +129,7 @@ public function table(Table $table): Table
public function render(): View
{
return view('shopper::livewire.pages.brand.index', [
'total' => (new BrandRepository())->count(),
'total' => (new BrandRepository)->count(),
])->title(__('shopper::pages/brands.menu'));
}
}
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new CategoryRepository())
(new CategoryRepository)
->makeModel()
->with('parent:id,name')
->newQuery()
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Pages/Collection/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new CollectionRepository())
(new CollectionRepository)
->makeModel()
->with('rules')
->newQuery()
Expand Down Expand Up @@ -88,7 +88,7 @@ public function table(Table $table): Table
public function render(): View
{
return view('shopper::livewire.pages.collections.browse', [
'total' => (new CollectionRepository())->count(),
'total' => (new CollectionRepository)->count(),
])
->title(__('shopper::pages/collections.menu'));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Customers/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function store(): void
]);

/** @var User $customer */
$customer = (new UserRepository())->create(array_merge(
$customer = (new UserRepository)->create(array_merge(
$customerData,
['email_verified_at' => now()->toDateTimeString()],
));
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Pages/Customers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new UserRepository())
(new UserRepository)
->with(['roles', 'addresses'])
->makeModel()
->scopes('customers')
Expand Down Expand Up @@ -99,7 +99,7 @@ public function table(Table $table): Table
public function render(): View
{
return view('shopper::livewire.pages.customers.index', [
'total' => (new UserRepository())
'total' => (new UserRepository)
->makeModel()
->scopes('customers')
->count(),
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Customers/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function mount(int $user): void
{
$this->authorize('read_customers');

$this->customer = (new UserRepository())->with(['addresses', 'orders'])->getById($user);
$this->customer = (new UserRepository)->with(['addresses', 'orders'])->getById($user);
}

public function render(): View
Expand Down
6 changes: 3 additions & 3 deletions packages/admin/src/Livewire/Pages/Product/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function mount(): void

$this->form->fill();

$this->defaultChannel = (new ChannelRepository())
$this->defaultChannel = (new ChannelRepository)
->where('is_default', true)
->first();
}
Expand Down Expand Up @@ -285,7 +285,7 @@ public function store(): void
$data = $this->form->getState();

/** @var Product $product */
$product = (new ProductRepository())->create(
$product = (new ProductRepository)->create(
Arr::except($data, ['quantity', 'categories'])
);
$this->form->model($product)->saveRelationships();
Expand All @@ -299,7 +299,7 @@ public function store(): void
$quantity = (int) $data['quantity'];

if ($quantity && $quantity > 0) {
(new InitialQuantityInventory())->handle($quantity, $product);
(new InitialQuantityInventory)->handle($quantity, $product);
}

Notification::make()
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Product/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function mount(): void
{
$this->authorize('edit_products');

$this->product = (new ProductRepository())->getById((int) $this->product);
$this->product = (new ProductRepository)->getById((int) $this->product);
}

public function deleteAction(): Action
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Pages/Product/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new ProductRepository())
(new ProductRepository)
->with(['brand', 'variants'])
->makeModel()
->newQuery()
Expand Down Expand Up @@ -137,7 +137,7 @@ public function table(Table $table): Table
public function render(): View
{
return view('shopper::livewire.pages.products.index', [
'total' => (new ProductRepository())->count(),
'total' => (new ProductRepository)->count(),
])
->title(__('shopper::pages/products.menu'));
}
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/Pages/Product/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function mount(int $product, int $variantId): void
{
$this->authorize('edit_products');

$this->product = (new ProductRepository())->getById($product);
$this->variant = (new ProductRepository())->getById($variantId);
$this->product = (new ProductRepository)->getById($product);
$this->variant = (new ProductRepository)->getById($variantId);

$this->form->fill($this->variant->toArray());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Livewire/Pages/Settings/Team/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function table(Table $table): Table
{
return $table
->query(
(new UserRepository())
(new UserRepository)
->with('roles')
->makeModel()
->scopes('administrators')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function form(Form $form): Form
public function store(): void
{
/** @var Collection $collection */
$collection = (new CollectionRepository())->create($this->form->getState());
$collection = (new CollectionRepository)->create($this->form->getState());
$this->form->model($collection)->saveRelationships();

Notification::make()
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Livewire/SlideOvers/AddVariantForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ public function save(): void
$data = $this->form->getState();

/** @var Product $product */
$product = (new ProductRepository())->create(
$product = (new ProductRepository)->create(
Arr::except($data, ['quantity'])
);
$this->form->model($product)->saveRelationships();

$quantity = (int) $data['quantity'];

if ($quantity && $quantity > 0) {
(new InitialQuantityInventory())->handle($quantity, $product);
(new InitialQuantityInventory)->handle($quantity, $product);
}

Notification::make()
Expand Down
6 changes: 3 additions & 3 deletions packages/admin/src/Livewire/SlideOvers/BrandForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class BrandForm extends SlideOverComponent implements HasForms
public function mount(?int $brandId = null): void
{
$this->brand = $brandId
? (new BrandRepository())->getById($brandId)
: (new BrandRepository())->makeModel();
? (new BrandRepository)->getById($brandId)
: (new BrandRepository)->makeModel();

$this->form->fill($this->brand->toArray());
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public function save(): void
if ($this->brand->id) {
$this->brand->update($this->form->getState());
} else {
$brand = (new BrandRepository())->create($this->form->getState());
$brand = (new BrandRepository)->create($this->form->getState());
$this->form->model($brand)->saveRelationships();
}

Expand Down
6 changes: 3 additions & 3 deletions packages/admin/src/Livewire/SlideOvers/CategoryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class CategoryForm extends SlideOverComponent implements HasForms
public function mount(?int $categoryId = null): void
{
$this->category = $categoryId
? (new CategoryRepository())->getById($categoryId)
: (new CategoryRepository())->makeModel();
? (new CategoryRepository)->getById($categoryId)
: (new CategoryRepository)->makeModel();

$this->form->fill($this->category->toArray());
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public function save(): void
if ($this->category->id) {
$this->category->update($this->form->getState());
} else {
$category = (new CategoryRepository())->create($this->form->getState());
$category = (new CategoryRepository)->create($this->form->getState());
$this->form->model($category)->saveRelationships();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function store(): void
$data = $this->form->getState();

/** @var User $user */
$user = (new UserRepository())->create([
$user = (new UserRepository)->create([
'email' => $data['email'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
Expand Down
Loading

0 comments on commit b90f387

Please sign in to comment.