-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from lara-zeus/embeddable
allow to embed the contact form
- Loading branch information
Showing
9 changed files
with
569 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div> | ||
@if($sent) | ||
@include('zeus-wind::submitted') | ||
@else | ||
<form wire:submit.prevent="store"> | ||
<div class="max-w-4xl mx-auto my-4"> | ||
{{ $this->form }} | ||
<div class="p-4 text-center"> | ||
<x-zeus::button type="submit">{{ __('Send') }}</x-zeus::button> | ||
</div> | ||
</div> | ||
</form> | ||
@endif | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace LaraZeus\Wind\Http\Livewire; | ||
|
||
use Filament\Forms; | ||
use Filament\Forms\Components\Grid; | ||
use Filament\Forms\Components\Textarea; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Forms\Components\ViewField; | ||
use LaraZeus\Wind\Events\LetterSent; | ||
use LaraZeus\Wind\Models\Department; | ||
use LaraZeus\Wind\Models\Letter; | ||
use Livewire\Component; | ||
|
||
class ContactsForm extends Component implements Forms\Contracts\HasForms | ||
{ | ||
use Forms\Concerns\InteractsWithForms; | ||
|
||
public Department|null $department = null; | ||
public $name = ''; | ||
public $email = ''; | ||
public $title = ''; | ||
public $message = ''; | ||
public $department_id; | ||
public $sent = false; | ||
public $status = 'NEW'; | ||
|
||
public function mount($departmentSlug) | ||
{ | ||
if (config('zeus-wind.enableDepartments')) { | ||
if ($departmentSlug !== null) { | ||
$this->department = Department::whereSlug($departmentSlug)->first(); | ||
} else { | ||
$this->department = Department::find(config('zeus-wind.defaultDepartmentId')); | ||
} | ||
} | ||
|
||
$this->form->fill( | ||
[ | ||
'department_id' => $this->department->id ?? 0, | ||
'status' => config('zeus-wind.default_status'), | ||
] | ||
); | ||
} | ||
|
||
public function store() | ||
{ | ||
$letter = Letter::create($this->form->getState()); | ||
$this->sent = true; | ||
LetterSent::dispatch($letter); | ||
} | ||
|
||
protected function getFormSchema(): array | ||
{ | ||
return [ | ||
Grid::make()->schema([ | ||
ViewField::make('department_id') | ||
->view('zeus-wind::departments') | ||
->columnSpan(2) | ||
->label(__('Departments')) | ||
->visible(fn (): bool => config('zeus-wind.enableDepartments')), | ||
|
||
TextInput::make('name')->required()->minLength('6')->label(__('name')), | ||
TextInput::make('email')->required()->email()->label(__('email')), | ||
])->columns(2), | ||
|
||
Grid::make()->schema([ | ||
TextInput::make('title')->required()->label(__('title')), | ||
Textarea::make('message')->required()->label(__('message')), | ||
])->columns(1), | ||
]; | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('zeus-wind::contact-form') | ||
->with('departments', Department::whereIsActive(1)->orderBy('ordering')->get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters