mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-26 09:02:53 -04:00 
			
		
		
		
	wip
This commit is contained in:
		
							parent
							
								
									ef3f77b82f
								
							
						
					
					
						commit
						cdd62f7e2a
					
				| @ -14,23 +14,33 @@ | |||||||
| namespace App\Http\Livewire; | namespace App\Http\Livewire; | ||||||
| 
 | 
 | ||||||
| use Illuminate\Support\Facades\Validator; | use Illuminate\Support\Facades\Validator; | ||||||
|  | use Illuminate\Support\Str; | ||||||
| use Livewire\Component; | use Livewire\Component; | ||||||
| 
 | 
 | ||||||
| class RequiredClientInfo extends Component | class RequiredClientInfo extends Component | ||||||
| { | { | ||||||
|     public $fields = []; |     public $fields = []; | ||||||
| 
 | 
 | ||||||
|  |     public $contact; | ||||||
|  | 
 | ||||||
|     private $gateway; |     private $gateway; | ||||||
| 
 | 
 | ||||||
|  |     private $mappings = [ | ||||||
|  |         'client_name' => 'name', | ||||||
|  | 
 | ||||||
|  |         'contact_phone' => 'phone', | ||||||
|  |     ]; | ||||||
|  | 
 | ||||||
|     public function handleSubmit(array $data): bool |     public function handleSubmit(array $data): bool | ||||||
|     { |     { | ||||||
|         $rules = []; |         $rules = []; | ||||||
| 
 | 
 | ||||||
|         collect($this->fields)->map(function ($field) use (&$rules) { |         collect($this->fields)->map(function ($field) use (&$rules) { | ||||||
|             $rules[$field['name']] = $field['validation_rules']; |             $rules[$field['name']] = array_key_exists('validation_rules', $field) | ||||||
|  |                 ? $field['validation_rules'] | ||||||
|  |                 : 'required'; | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         $validator = Validator::make($data, $rules); |         $validator = Validator::make($data, $rules); | ||||||
| 
 | 
 | ||||||
|         if ($validator->fails()) { |         if ($validator->fails()) { | ||||||
| @ -39,25 +49,60 @@ class RequiredClientInfo extends Component | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         if ($this->updateClientDetails($data)) { | ||||||
|             $this->emit('passed-required-fields-check'); |             $this->emit('passed-required-fields-check'); | ||||||
| 
 | 
 | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // TODO: Throw an exception about not being able to update the profile.
 | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private function updateClientDetails(array $data): bool | ||||||
|  |     { | ||||||
|  |         $client = []; | ||||||
|  |         $contact = []; | ||||||
|  | 
 | ||||||
|  |         foreach ($data as $field => $value) { | ||||||
|  |             if (Str::startsWith($field, 'client_', )) { | ||||||
|  |                 $client[$this->mappings[$field]] = $value; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (Str::startsWith($field, 'contact_')) { | ||||||
|  |                 $contact[$this->mappings[$field]] = $value; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         $contact_update = $this->contact | ||||||
|  |             ->fill($contact) | ||||||
|  |             ->push(); | ||||||
|  | 
 | ||||||
|  |         $client_update = $this->contact->client | ||||||
|  |             ->fill($client) | ||||||
|  |             ->push(); | ||||||
|  | 
 | ||||||
|  |         if ($contact_update && $client_update) { | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function render() |     public function render() | ||||||
|     { |     { | ||||||
|         // This will be coming from the gateway itself. Something like $gateway->getRequiredRules();
 |         // This will be coming from the gateway itself. Something like $gateway->getRequiredRules();
 | ||||||
| 
 | 
 | ||||||
|         $this->fields = [ |         $this->fields = [ | ||||||
|             [ |             [ | ||||||
|                 'name' => 'client_first_name', |                 'name' => 'client_name', | ||||||
|                 'label' => ctrans('texts.first_name'), |                 'label' => ctrans('texts.name'), | ||||||
|                 'type' => 'text', |                 'type' => 'text', | ||||||
|                 'validation_rules' => 'required|min:3' |                 'validation_rules' => 'required|min:3' | ||||||
|             ], |             ], | ||||||
|             [ |             [ | ||||||
|                 'name' => 'client_billing_address_zip', |                 'name' => 'contact_phone', | ||||||
|                 'label' => ctrans('texts.postal_code'), |                 'label' => ctrans('texts.phone'), | ||||||
|                 'type' => 'number', |                 'type' => 'number', | ||||||
|                 'validation_rules' => 'required|min:2', |                 'validation_rules' => 'required|min:2', | ||||||
|             ], |             ], | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ | |||||||
| @endpush | @endpush | ||||||
| 
 | 
 | ||||||
| @section('body') | @section('body') | ||||||
|     @livewire('required-client-info', ['gateway' => $gateway]) |     @livewire('required-client-info', ['gateway' => $gateway, 'contact' => auth('contact')->user()]) | ||||||
| 
 | 
 | ||||||
|     <div class="container mx-auto grid grid-cols-12 hidden" data-ref="gateway-container"> |     <div class="container mx-auto grid grid-cols-12 hidden" data-ref="gateway-container"> | ||||||
|         <div class="col-span-12 lg:col-span-6 lg:col-start-4 overflow-hidden bg-white shadow rounded-lg"> |         <div class="col-span-12 lg:col-span-6 lg:col-start-4 overflow-hidden bg-white shadow rounded-lg"> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user