diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 4374ce485d39..1b531b202645 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -978,19 +978,50 @@ class ClientPortalController extends BaseController return view('invited.details', $data); } - public function updateDetails() + public function updateDetails(\Illuminate\Http\Request $request) { if (! $contact = $this->getContact()) { return $this->returnError(); } + $client = $contact->client; + $account = $contact->account; + + if (! $account->enable_client_portal || ! $account->enable_client_portal_dashboard) { + return $this->returnError(); + } + + $rules = [ + 'address1' => 'required', + 'city' => 'required', + 'state' => 'required', + 'postal_code' => 'required', + 'country_id' => 'required', + ]; + + if ($client->name) { + $rules['name'] = 'required'; + } else { + $rules['first_name'] = 'required'; + $rules['last_name'] = 'required'; + } + if (! $contact->email) { + $rules['email'] = 'required'; + } + if ($account->vat_number) { + $rules['vat_number'] = 'required'; + } + + $this->validate($request, $rules); + $contact->fill(request()->all()); $contact->save(); - $client = $contact->client; $client->fill(request()->all()); $client->save(); - return redirect('/client/dashboard'); + event(new \App\Events\ClientWasUpdated($client)); + + return redirect('/client/dashboard')->withMessage(trans('texts.updated_client_details')); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3916204a2264..546c15e9c8f0 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2653,6 +2653,7 @@ $LANG = array( 'amount_greater_than_balance' => 'The amount is greater than the invoice balance, a credit will be created with the remaining amount.', 'custom_fields_tip' => 'Use Label|Option1,Option2 to show a select box.', 'client_information' => 'Client Information', + 'updated_client_details' => 'Successfully updated client details', ); diff --git a/resources/views/invited/dashboard.blade.php b/resources/views/invited/dashboard.blade.php index c966133bea2a..28e14ca0b504 100644 --- a/resources/views/invited/dashboard.blade.php +++ b/resources/views/invited/dashboard.blade.php @@ -352,7 +352,7 @@ @if ($client->hasRecurringInvoices()) {!! Button::primary(strtoupper(trans("texts.recurring")))->asLinkTo(URL::to('/client/invoices/recurring')) !!} @endif - {!! Button::success(strtoupper(trans("texts.edit_details")))->asLinkTo(URL::to('/client/details')) !!} + {!! Button::success(strtoupper(trans("texts.edit_details")))->asLinkTo(URL::to('/client/details'))->withAttributes(['id' => 'editDetailsButton']) !!} diff --git a/resources/views/invited/details.blade.php b/resources/views/invited/details.blade.php index 228f4b993aa5..b91d865f1568 100644 --- a/resources/views/invited/details.blade.php +++ b/resources/views/invited/details.blade.php @@ -30,7 +30,6 @@ 'country_id' => 'required', )) !!} - @if ($client) {{ Former::populate($client) }} {{ Former::populateField('first_name', $contact->first_name) }}