Merge pull request #2299 from pavel-mironchik/fix-select-contact

Fix passing custom routes to the SelectContactCard component.
This commit is contained in:
Cüneyt Şentürk 2021-11-03 15:24:21 +03:00 committed by GitHub
commit 4d9de067e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 20 deletions

View File

@ -16,9 +16,9 @@ class SelectContactCard extends Component
public $contacts; public $contacts;
public $search_route; public $searchRoute;
public $create_route; public $createRoute;
/** @var string */ /** @var string */
public $textAddContact; public $textAddContact;
@ -44,15 +44,15 @@ class SelectContactCard extends Component
* @return void * @return void
*/ */
public function __construct( public function __construct(
$type, $contact = false, $contacts = [], $search_route = '', $create_route = '', string $error = '', $type, $contact = false, $contacts = [], $searchRoute = '', $createRoute = '', string $error = '',
$textAddContact = '', $textCreateNewContact = '', $textEditContact = '', $textContactInfo = '', $textChooseDifferentContact = '' $textAddContact = '', $textCreateNewContact = '', $textEditContact = '', $textContactInfo = '', $textChooseDifferentContact = ''
) )
{ {
$this->type = $type; $this->type = $type;
$this->contact = $contact; $this->contact = $contact;
$this->contacts = $contacts; $this->contacts = $contacts;
$this->search_route = $search_route; $this->searchRoute = $searchRoute;
$this->create_route = $create_route; $this->createRoute = $createRoute;
$this->error = ($error) ?: "form.errors.get('contact_id')" ; $this->error = ($error) ?: "form.errors.get('contact_id')" ;
$this->textAddContact = $this->getTextAddContact($type, $textAddContact); $this->textAddContact = $this->getTextAddContact($type, $textAddContact);
@ -73,24 +73,24 @@ class SelectContactCard extends Component
$this->contacts = Contact::{$this->type}()->enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); $this->contacts = Contact::{$this->type}()->enabled()->orderBy('name')->take(setting('default.select_limit'))->get();
} }
if (empty($this->search_route)) { if (empty($this->searchRoute)) {
switch ($this->type) { switch ($this->type) {
case 'customer': case 'customer':
$this->search_route = route('customers.index'); $this->searchRoute = route('customers.index');
break; break;
case 'vendor': case 'vendor':
$this->search_route = route('vendors.index'); $this->searchRoute = route('vendors.index');
break; break;
} }
} }
if (empty($this->create_route)) { if (empty($this->createRoute)) {
switch ($this->type) { switch ($this->type) {
case 'customer': case 'customer':
$this->create_route = route('modals.customers.create'); $this->createRoute = route('modals.customers.create');
break; break;
case 'vendor': case 'vendor':
$this->create_route = route('modals.vendors.create'); $this->createRoute = route('modals.vendors.create');
break; break;
} }
} }
@ -100,7 +100,7 @@ class SelectContactCard extends Component
return view('components.select-contact-card'); return view('components.select-contact-card');
} }
protected function getTextAddContact($type, $textAddContact) protected function getTextAddContact($type, $textAddContact)
{ {
if (!empty($textAddContact)) { if (!empty($textAddContact)) {

View File

@ -40,8 +40,8 @@
contact-type="{{ $contactType }}" contact-type="{{ $contactType }}"
:contact="$contact" :contact="$contact"
:contacts="$contacts" :contacts="$contacts"
:search_route="$contactSearchRoute" :search-route="$contactSearchRoute"
:create_route="$contactCreateRoute" :create-route="$contactCreateRoute"
hide-issued-at="{{ $hideIssuedAt }}" hide-issued-at="{{ $hideIssuedAt }}"
text-issued-at="{{ $textIssuedAt }}" text-issued-at="{{ $textIssuedAt }}"
issued-at="{{ $issuedAt }}" issued-at="{{ $issuedAt }}"

View File

@ -11,8 +11,8 @@
contact-type="{{ $contactType }}" contact-type="{{ $contactType }}"
:contact="$contact" :contact="$contact"
:contacts="$contacts" :contacts="$contacts"
:search_route="$contactSearchRoute" :search-route="$contactSearchRoute"
:create_route="$contactCreateRoute" :create-route="$contactCreateRoute"
hide-issued-at="{{ $hideIssuedAt }}" hide-issued-at="{{ $hideIssuedAt }}"
text-issued-at="{{ $textIssuedAt }}" text-issued-at="{{ $textIssuedAt }}"
issued-at="{{ $issuedAt }}" issued-at="{{ $issuedAt }}"

View File

@ -6,8 +6,8 @@
type="{{ $contactType }}" type="{{ $contactType }}"
:contact="$contact" :contact="$contact"
:contacts="$contacts" :contacts="$contacts"
:search_route="$contactSearchRoute" :search-route="$contactSearchRoute"
:create_route="$contactCreateRoute" :create-route="$contactCreateRoute"
error="form.errors.get('contact_name')" error="form.errors.get('contact_name')"
:text-add-contact="$textAddContact" :text-add-contact="$textAddContact"
:text-create-new-contact="$textCreateNewContact" :text-create-new-contact="$textCreateNewContact"

View File

@ -2,8 +2,8 @@
placeholder="{{ $placeholder }}" placeholder="{{ $placeholder }}"
no-data-text="{{ trans('general.no_data') }}" no-data-text="{{ trans('general.no_data') }}"
no-matching-data-text="{{ trans('general.no_matching_data') }}" no-matching-data-text="{{ trans('general.no_matching_data') }}"
search-route="{{ $search_route }}" search-route="{{ $searchRoute }}"
create-route="{{ $create_route }}" create-route="{{ $createRoute }}"
:contacts="{{ json_encode($contacts) }}" :contacts="{{ json_encode($contacts) }}"
:selected="{{ json_encode($contact) }}" :selected="{{ json_encode($contact) }}"
add-contact-text="{{ is_array($textAddContact) ? trans($textAddContact[0], ['field' => trans_choice($textAddContact[1], 1)]) : trans($textAddContact) }}" add-contact-text="{{ is_array($textAddContact) ? trans($textAddContact[0], ['field' => trans_choice($textAddContact[1], 1)]) : trans($textAddContact) }}"