From a2796a5631c3a4a2a1db81e768b3a5ff300c7778 Mon Sep 17 00:00:00 2001 From: Rahman Ramsi Date: Thu, 21 Dec 2023 09:11:38 +0800 Subject: [PATCH] fix condition --- .../Livewire/Submissions/Forms/Publish.php | 1 - .../Pages/ViewSubmission.php | 148 +++++++++++------- 2 files changed, 92 insertions(+), 57 deletions(-) diff --git a/app/Panel/Livewire/Submissions/Forms/Publish.php b/app/Panel/Livewire/Submissions/Forms/Publish.php index eebacc009..9e3524558 100644 --- a/app/Panel/Livewire/Submissions/Forms/Publish.php +++ b/app/Panel/Livewire/Submissions/Forms/Publish.php @@ -86,7 +86,6 @@ public function publishAction() ->modalSubmitAction(false) ) ->when( - // true, fn () => ! $this->submission->hasPaymentProcess() || $this->submission->payment?->isCompleted(), fn (Action $action): Action => $action ->successNotificationTitle('Submission published successfully') diff --git a/app/Panel/Resources/SubmissionResource/Pages/ViewSubmission.php b/app/Panel/Resources/SubmissionResource/Pages/ViewSubmission.php index 3490b2acd..b33159997 100644 --- a/app/Panel/Resources/SubmissionResource/Pages/ViewSubmission.php +++ b/app/Panel/Resources/SubmissionResource/Pages/ViewSubmission.php @@ -13,6 +13,7 @@ use App\Models\Enums\SubmissionStage; use App\Models\Enums\SubmissionStatus; use App\Models\Enums\UserRole; +use App\Models\Payment; use App\Models\PaymentItem; use App\Models\User; use App\Notifications\SubmissionWithdrawn; @@ -23,7 +24,6 @@ use App\Panel\Livewire\Submissions\Forms\Detail; use App\Panel\Livewire\Submissions\Forms\Publish; use App\Panel\Livewire\Submissions\Forms\References; -use App\Panel\Livewire\Submissions\Payment; use App\Panel\Livewire\Submissions\PeerReview; use App\Panel\Livewire\Workflows\Classes\StageManager; use App\Panel\Livewire\Workflows\Concerns\InteractWithTenant; @@ -70,6 +70,21 @@ public function mount($record): void abort_unless(static::getResource()::canView($this->getRecord()), 403); } + /** + * @return array + */ + public function getBreadcrumbs(): array + { + $resource = static::getResource(); + + $breadcrumb = $this->getBreadcrumb(); + + return [ + $resource::getUrl() => $resource::getBreadcrumb(), + ...(filled($breadcrumb) ? [$breadcrumb] : []), + ]; + } + protected function getHeaderActions(): array { return [ @@ -81,7 +96,18 @@ protected function getHeaderActions(): array ->color('primary') ->modalHeading('Submission Payment') ->when( - fn (Action $action): bool => ! $action->getRecord() || $action->getRecord()?->state->isOneOf(PaymentState::Unpaid), + fn (Action $action) => !FacadesPayment::driver($action->getRecord()?->payment_method), + fn (Action $action) => $action + ->modalContent(function($action){ + $paymentMethod = $action->getRecord()?->payment_method ?? FacadesPayment::getDefaultDriver(); + + return new HtmlString("

There's a problem with configured payment method. Please contact administrator.
Payment method : " . $paymentMethod . "

"); + }) + ->modalWidth('xl') + ->modalSubmitAction(false), + ) + ->when( + fn (Action $action): bool => FacadesPayment::driver() && (!$action->getRecord() || $action->getRecord()?->state->isOneOf(PaymentState::Unpaid) && FacadesPayment::driver()), fn (Action $action): Action => $action ->action(function (array $data, Form $form) { @@ -94,56 +120,64 @@ protected function getHeaderActions(): array $form->model($payment)->saveRelationships(); - FacadesPayment::driver($this->record->payment?->payment_method)->handlePayment($payment); - })->mountUsing(function (Form $form) { - $payment = $this->record->payment; + $paymentDriver = FacadesPayment::driver($payment?->payment_method); + + $paymentDriver->handlePayment($payment); + })->mountUsing(function (Form $form, ?Payment $record) { + + $paymentDriver = FacadesPayment::driver($record?->payment_method); $form->fill([ - 'currency_id' => $payment?->currency_id, - ...FacadesPayment::getPaymentFormFill(), + 'currency_id' => $record?->currency_id, + ...$paymentDriver->getPaymentFormFill(), ]); - })->form([ - Select::make('currency_id') - ->label('Currency') - ->options( - Currency::query() - ->whereIn('id', App::getCurrentConference()->getSupportedCurrencies()) - ->get() - ->mapWithKeys(fn (Currency $currency) => [$currency->id => $currency->name.' ('.$currency->symbol_native.')']) - ) - ->required() - ->reactive(), - CheckboxList::make('items') - ->visible(fn (Get $get) => $get('currency_id')) - ->required() - ->options(function (Get $get) { - return PaymentItem::get() - ->filter(function (PaymentItem $item) use ($get): bool { - foreach ($item->fees as $fee) { - if (! array_key_exists('currency_id', $fee)) { - continue; - } - if ($fee['currency_id'] === $get('currency_id')) { - return true; + })->form(function (?Payment $record) { + + $paymentDriver = FacadesPayment::driver($record?->payment_method); + + return [ + Select::make('currency_id') + ->label('Currency') + ->options( + Currency::query() + ->whereIn('id', App::getCurrentConference()->getSupportedCurrencies()) + ->get() + ->mapWithKeys(fn (Currency $currency) => [$currency->id => $currency->name . ' (' . $currency->symbol_native . ')']) + ) + ->required() + ->reactive(), + CheckboxList::make('items') + ->visible(fn (Get $get) => $get('currency_id')) + ->required() + ->options(function (Get $get) { + return PaymentItem::get() + ->filter(function (PaymentItem $item) use ($get): bool { + foreach ($item->fees as $fee) { + if (!array_key_exists('currency_id', $fee)) { + continue; + } + if ($fee['currency_id'] === $get('currency_id')) { + return true; + } } - } - - return false; - }) - // ->mapWithKeys(fn (PaymentItem $item): array => [$item->getAmount($get('currency_id')) => $item->name . ': ' . $item->getFormattedAmount($get('currency_id'))]); - ->mapWithKeys(fn (PaymentItem $item): array => [$item->id => $item->name.': '.$item->getFormattedAmount($get('currency_id'))]); - }), - ...FacadesPayment::driver($this->record->payment?->payment_method)->getPaymentFormSchema(), - ]), + + return false; + }) + // ->mapWithKeys(fn (PaymentItem $item): array => [$item->getAmount($get('currency_id')) => $item->name . ': ' . $item->getFormattedAmount($get('currency_id'))]); + ->mapWithKeys(fn (PaymentItem $item): array => [$item->id => $item->name . ': ' . $item->getFormattedAmount($get('currency_id'))]); + }), + ...$paymentDriver->getPaymentFormSchema() ?? [], + ]; + }), ) ->when( - fn (Action $action): bool => $action->getRecord()?->state->isOneOf(PaymentState::Processing, PaymentState::Paid, PaymentState::Waived) ?? false, + fn (Action $action): bool => FacadesPayment::driver($action->getRecord()?->payment_method) && $action->getRecord()?->state->isOneOf(PaymentState::Processing, PaymentState::Paid, PaymentState::Waived), fn (Action $action): Action => $action ->action(function (array $data, $record) { $record->state = $data['decision']; $record->save(); }) - ->modalSubmitAction(fn (StaticAction $action) => $action->hidden($this->record->payment?->isCompleted())) - ->modalCancelAction(fn (StaticAction $action) => $action->hidden($this->record->payment?->isCompleted())) + ->modalSubmitAction(fn (StaticAction $action, ?Payment $record) => $action->visible(auth()->user()->can('update', $record))) + ->modalCancelAction(fn (StaticAction $action, ?Payment $record) => $action->visible(auth()->user()->can('update', $record))) ->mountUsing(function (Form $form) { $payment = $this->record->payment; @@ -153,6 +187,8 @@ protected function getHeaderActions(): array 'items' => array_keys($payment?->getMeta('items') ?? []), ...FacadesPayment::driver($payment?->payment_method)?->getPaymentFormFill() ?? [], ]); + + $form->disabled(fn ($record) => !auth()->user()->can('update', $record)); }) ->form([ Grid::make(1) @@ -174,7 +210,7 @@ protected function getHeaderActions(): array ->disabled(), Select::make('decision') ->required() - ->hidden(fn () => $this->record->payment?->isCompleted()) + ->visible(fn ($record) => auth()->user()->can('update', $record)) ->options([ PaymentState::Unpaid->value => PaymentState::Unpaid->name, PaymentState::Waived->value => PaymentState::Waived->name, @@ -254,7 +290,7 @@ protected function getHeaderActions(): array ->color('danger') ->extraAttributes(function (Action $action) { if (filled($this->record->withdrawn_reason)) { - $attributeValue = '$nextTick(() => { $wire.mountAction(\''.$action->getName().'\') })'; + $attributeValue = '$nextTick(() => { $wire.mountAction(\'' . $action->getName() . '\') })'; return [ 'x-init' => new HtmlString($attributeValue), @@ -278,7 +314,7 @@ protected function getHeaderActions(): array ]) ->requiresConfirmation() ->modalHeading(function () { - return $this->record->user->fullName.' has requested to withdraw this submission.'; + return $this->record->user->fullName . ' has requested to withdraw this submission.'; }) ->modalDescription("You can either reject the request or accept it, remember it can't be undone.") ->modalCancelActionLabel('Ignore') @@ -325,13 +361,13 @@ public function getSubheading(): string|Htmlable|null $badgeHtml = '
'; $badgeHtml .= match ($this->record->status) { - SubmissionStatus::Incomplete => ''.SubmissionStatus::Incomplete->value.'', - SubmissionStatus::Queued => ''.SubmissionStatus::Queued->value.'', - SubmissionStatus::OnReview => ''.SubmissionStatus::OnReview->value.'', - SubmissionStatus::Published => ''.SubmissionStatus::Published->value.'', - SubmissionStatus::Editing => ''.SubmissionStatus::Editing->value.'', - SubmissionStatus::Declined => ''.SubmissionStatus::Declined->value.'', - SubmissionStatus::Withdrawn => ''.SubmissionStatus::Withdrawn->value.'', + SubmissionStatus::Incomplete => '' . SubmissionStatus::Incomplete->value . '', + SubmissionStatus::Queued => '' . SubmissionStatus::Queued->value . '', + SubmissionStatus::OnReview => '' . SubmissionStatus::OnReview->value . '', + SubmissionStatus::Published => '' . SubmissionStatus::Published->value . '', + SubmissionStatus::Editing => '' . SubmissionStatus::Editing->value . '', + SubmissionStatus::Declined => '' . SubmissionStatus::Declined->value . '', + SubmissionStatus::Withdrawn => '' . SubmissionStatus::Withdrawn->value . '', default => null, }; @@ -382,7 +418,7 @@ public function infolist(Infolist $infolist): Infolist Tab::make('Call for Abstract') ->icon('heroicon-o-information-circle') ->schema(function () { - if (! StageManager::callForAbstract()->isStageOpen() && ! $this->record->isPublished()) { + if (!StageManager::callForAbstract()->isStageOpen() && !$this->record->isPublished()) { return [ ShoutEntry::make('call-for-abstract-closed') ->type('warning') @@ -401,7 +437,7 @@ public function infolist(Infolist $infolist): Infolist Tab::make('Peer Review') ->icon('iconpark-checklist-o') ->schema(function (): array { - if (! StageManager::peerReview()->isStageOpen() && ! $this->record->isPublished()) { + if (!StageManager::peerReview()->isStageOpen() && !$this->record->isPublished()) { return [ ShoutEntry::make('peer-review-closed') ->type('warning') @@ -420,7 +456,7 @@ public function infolist(Infolist $infolist): Infolist Tab::make('Editing') ->icon('heroicon-o-pencil') ->schema(function () { - if (! StageManager::editing()->isStageOpen() && ! $this->record->isPublished()) { + if (!StageManager::editing()->isStageOpen() && !$this->record->isPublished()) { return [ ShoutEntry::make('editing-closed') ->type('warning') @@ -468,7 +504,7 @@ public function infolist(Infolist $infolist): Infolist LivewireEntry::make('contributors') ->livewire(ContributorList::class, [ 'submission' => $this->record, - 'viewOnly' => ! auth()->user()->can('editing', $this->record), + 'viewOnly' => !auth()->user()->can('editing', $this->record), ]), ]), Tab::make('References')