Skip to content

Commit

Permalink
consent option dynamic fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AravindRam-Ranium committed Feb 16, 2024
1 parent 3ac99d8 commit 0cdc409
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 2 additions & 0 deletions database/migrations/create_user_consent_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ return new class extends Migration
$table->string('title')->nullable()->default(null);
$table->string('label')->nullable()->default(null);
$table->text('text')->nullable()->default(null);
$table->boolean('additional_info')->default(0);
$table->json('fields')->nullable();
$table->boolean('is_mandatory')->default(0);
$table->boolean('is_current')->default(0);
$table->boolean('enabled')->default(0);
Expand Down
4 changes: 1 addition & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
use Visualbuilder\FilamentUserConsent\Livewire\ConsentOptionRequest;

//Routes for users to view and save their consent
// Route::middleware(['auth:admin,practitioner,enduser'])->group(function () {
Route::get('consent-option-request', ConsentOptionRequest::class)->name('consent-option-request');
// });
Route::get('consent-option-request', ConsentOptionRequest::class)->name('consent-option-request');
2 changes: 2 additions & 0 deletions src/Models/ConsentOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ConsentOption extends Model
'title',
'label',
'text',
'fields',
'is_mandatory',
'force_user_update',
'is_current',
Expand All @@ -65,6 +66,7 @@ class ConsentOption extends Model
protected $casts = [
'models' => 'array',
'published_at' => 'datetime:Y-m-d H:i:s',
'fields' => 'array'
// 'enabled' => 'boolean',
// 'is_current' => 'boolean',
// 'force_user_update' => 'boolean',
Expand Down
40 changes: 38 additions & 2 deletions src/Resources/ConsentOptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

namespace Visualbuilder\FilamentUserConsent\Resources;

use Closure;
use Filament\Forms;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Visualbuilder\FilamentUserConsent\Models\ConsentOption;
use Visualbuilder\FilamentUserConsent\Resources\ConsentOptionResource\Pages\CreateConsentOption;
Expand Down Expand Up @@ -46,7 +50,7 @@ public static function form(Form $form): Form
)
->required(),
Forms\Components\TextInput::make('key')
// ->unique(ignorable: fn ($record) => $record)
->unique(ignorable: fn ($record) => $record)
->required(),
Forms\Components\TextInput::make('label')
->hint('(For checkbox)')
Expand All @@ -55,7 +59,6 @@ public static function form(Form $form): Form
->numeric()
->required(),


Forms\Components\Toggle::make('enabled')
->label('Enable this contract')
->required(),
Expand Down Expand Up @@ -85,7 +88,40 @@ public static function form(Form $form): Form
->label('Contract text')
->required()
->columnSpanFull(),

Forms\Components\Toggle::make('additional_info')
->label('Do you want to demand additional info from user?')
->required()
->live()
->columnSpanFull(),
])->columns(3),
Section::make('Additional Info')->schema([
Repeater::make('fields')->label('')
->schema([
Forms\Components\TextInput::make('name')->required(),
Forms\Components\Select::make('type')
->options([
'text' => 'Text Input',
'email' => 'Email Input',
'number' => 'Number Input',
'date' => 'Date Picker',
'datetime' => 'Date & Time Picker',
'textarea' => 'Text area',
'select' => 'Select dropdown',
'radio' => 'Radio dropdown',
'check' => 'Checkbox',
])
->required(),
Forms\Components\TextInput::make('label')->required(),
Forms\Components\TagsInput::make('options')->separator(',')->splitKeys(['Tab', ' ']),
Forms\Components\TagsInput::make('rules')->separator(',')->splitKeys(['Tab', ' ']),
Forms\Components\Toggle::make('required')->inline(false)->required(),
])
->defaultItems(1)
->columns(3)
->addActionLabel('Add Field')
->collapsed()
])->visible(fn(Get $get) => (bool)$get('additional_info'))
]);
}

Expand Down

0 comments on commit 0cdc409

Please sign in to comment.