Skip to content

Commit

Permalink
Merge pull request #12 from lara-zeus/embeddable
Browse files Browse the repository at this point in the history
allow to embed the contact form
  • Loading branch information
atmonshi authored Jun 21, 2022
2 parents d9c7c3f + 0cf752a commit 76fc11e
Show file tree
Hide file tree
Showing 9 changed files with 569 additions and 480 deletions.
10 changes: 2 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"require": {
"php": "^8.0",
"lara-zeus/core": "dev-main"
"lara-zeus/core": "^2.0"
},
"require-dev": {
"orchestra/testbench": "^6.0 || ^7.0"
Expand All @@ -43,11 +43,5 @@
"Wind": "LaraZeus\\Wind\\WindFacade"
}
}
},
"repositories": [
{
"type": "path",
"url": "../core"
}
]
}
}
842 changes: 457 additions & 385 deletions composer.lock

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions resources/views/contact-form.blade.php
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>
13 changes: 1 addition & 12 deletions resources/views/contact.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,5 @@
{{ __('feel free to contact us.') }}
</x-zeus::box>

@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
<livewire:contact-form :departmentSlug="$departmentSlug" />
</div>
17 changes: 9 additions & 8 deletions resources/views/departments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
{{ __('Select Department') }}:
@error($getStatePath()) <p class="text-red-500">{{ $message }}</p> @enderror
</div>

<div class="max-w-4xl mx-auto my-6 grid grid-cols-1 sm:grid-cols-3 lg:grid-cols-4 gap-2 ">
@foreach($departments as $dept)
<div>
<label class="checkbox-wrapper">
<input wire:model="{{ $getStatePath() }}" @checked($departments->count() === 1) type="radio" class="checkbox-input" name="group" value="{{ $dept->id }}"/>
<input wire:model="{{ $getStatePath() }}" {{--@checked($departments->count() === 1 || request('department') === $dept->slug)--}} type="radio" class="checkbox-input" name="group" value="{{ $dept->id }}"/>
<span class="checkbox-tile hover:border-secondary-500 p-4">
<span class="text-primary-600 flex flex-col items-center justify-center gap-2">
@if($dept->logo !== null)
<img class="w-full h-32 object-center object-cover" src="{{ \Illuminate\Support\Facades\Storage::disk(config('zeus-wind.uploads.disk','public'))->url($dept->logo) }}">
@endif
{{ $dept->name ?? '' }}
</span>
<span class="text-gray-500 text-center px-2 overflow-clip overflow-hidden ">{{ $dept->desc ?? '' }}</span>
<span class="text-primary-600 flex flex-col items-center justify-center gap-2">
@if($dept->logo !== null)
<img class="w-full h-32 object-center object-cover" src="{{ \Illuminate\Support\Facades\Storage::disk(config('zeus-wind.uploads.disk','public'))->url($dept->logo) }}">
@endif
{{ $dept->name ?? '' }}
</span>
<span class="text-gray-500 text-center px-2 overflow-clip overflow-hidden ">{{ $dept->desc ?? '' }}</span>
</span>
</label>
</div>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Resources/DepartmentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function table(Table $table): Table
->label(__('name'))
->sortable()
->searchable()
->url(fn (Department $record): string => route('contact', ['department' => $record]))
->url(fn (Department $record): string => route('contact', ['departmentSlug' => $record]))
->openUrlInNewTab(),
TextColumn::make('desc')->label(__('desc')),
TextColumn::make('ordering')->sortable()->label(__('ordering')),
Expand Down
70 changes: 4 additions & 66 deletions src/Http/Livewire/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,15 @@

namespace LaraZeus\Wind\Http\Livewire;

use Filament\Forms;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Hidden;
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 Contacts extends Component implements Forms\Contracts\HasForms
class Contacts extends Component
{
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 $departmentSlug = null;

public function mount($departmentSlug = null)
{
if (config('zeus-wind.enableDepartments')) {
if ($departmentSlug !== null) {
$this->department = Department::whereSlug($departmentSlug)->first();
}

if ($this->department === null) {
$this->department = Department::find(config('zeus-wind.defaultDepartmentId'));
}
}

$this->form->fill(
['department_id' => $this->department->id ?? 0]
);
}

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),

Hidden::make('status')->default(config('zeus-wind.default_status')),
];
$this->departmentSlug = $departmentSlug;
}

public function render()
Expand All @@ -84,8 +24,6 @@ public function render()
->withUrl()
->twitter();

return view('zeus-wind::contact')
->with('departments', Department::whereIsActive(1)->orderBy('ordering')->get())
->layout(config('zeus-wind.layout'));
return view('zeus-wind::contact')->layout(config('zeus-wind.layout'));
}
}
79 changes: 79 additions & 0 deletions src/Http/Livewire/ContactsForm.php
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());
}
}
2 changes: 2 additions & 0 deletions src/WindServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use LaraZeus\Wind\Filament\Resources\DepartmentResource;
use LaraZeus\Wind\Filament\Resources\LetterResource;
use LaraZeus\Wind\Http\Livewire\Contacts;
use LaraZeus\Wind\Http\Livewire\ContactsForm;
use Livewire\Livewire;
use Spatie\LaravelPackageTools\Package;

Expand All @@ -25,6 +26,7 @@ protected function getResources(): array
public function boot()
{
Livewire::component('contact', Contacts::class);
Livewire::component('contact-form', ContactsForm::class);

if ($this->app->runningInConsole()) {
$this->publishes([
Expand Down

0 comments on commit 76fc11e

Please sign in to comment.