Skip to content

Instantly share code, notes, and snippets.

@ardzz
Last active May 4, 2024 11:57
Show Gist options
  • Save ardzz/9e4e857cd72c8c4ff76da02e94a473cc to your computer and use it in GitHub Desktop.
Save ardzz/9e4e857cd72c8c4ff76da02e94a473cc to your computer and use it in GitHub Desktop.
<?php
namespace App\Filament\Patient\Pages;
use App\Models\User;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Pages\Page;
use Illuminate\Support\HtmlString;
use Livewire\Component as Livewire;
use Midtrans\Snap;
class RequestExam extends Page implements HasForms, HasActions
{
use InteractsWithForms, InteractsWithActions;
protected static ?string $navigationIcon = 'heroicon-o-document-text';
protected static string $view = 'filament.pages.dokter';
public ?array $data = [];
public function mount(): void
{
$this->form->fill([
'name' => auth()->user()->name,
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Wizard::make()
->steps([
Wizard\Step::make('Isi Data')
->icon('heroicon-o-user-circle')
->schema([
TextInput::make('name')
->label('Nama Pemohon')
->disabled(),
Textarea::make('purpose')
->helperText('Tuliskan keperluan anda mengikuti psikotest MMPI-2, seperti keperluan pekerjaan, pendidikan, atau lainnya.')
->label('Keperluan Mengikuti Psikotest MMPI-2')
->required(),
Select::make('doctor')
->label('Dokter')
->options(fn() => User::doctors()->pluck('name', 'id')->toArray())
->lazy()
->searchable()
->native(false),
Checkbox::make('is_agree')
->required()
->label(new HtmlString('Saya setuju dengan <a href="#"><strong>Syarat dan Ketentuan</strong></a> yang berlaku.'))
]),
Wizard\Step::make('Pembayaran')
->icon('heroicon-o-credit-card')
->schema([
Select::make('payment_method')
->label('Metode Pembayaran')
->options([
'cash' => 'Transfer Bank Manual',
'midtrans' => 'Midtrans',
])
->native(false)
->live()
->suffixIcon('heroicon-o-currency-dollar')
->required()
->afterStateUpdated(function (Get $get, Livewire $livewire){
if ($get('payment_method') === 'midtrans') {
$params = [
'transaction_details' => [
'order_id' => rand(),
'gross_amount' => 10000,
],
'customer_details' => [
'first_name' => auth()->user()->name,
'email' => auth()->user()->email,
]
];
$snap_code = Snap::getSnapToken($params);
$livewire->js('snap.pay("'.$snap_code.'");');
}
}),
Section::make('Formulir Pembayaran')
->schema([
TextInput::make('sender_bank')
->label('Nama Bank')
->helperText('Contoh: BCA, BNI, BRI, Mandiri, dll.')
->required(),
TextInput::make('sender_name')
->label('Nama Pengirim')
->required(),
TextInput::make('sender_account')
->label('Nomor Rekening Pengirim')
->placeholder('1234567890')
->required(),
SpatieMediaLibraryFileUpload::make('proof_of_payment')
->label('Bukti Pembayaran')
->image()
->imageEditor()
->required()
])
->visible(fn (Get $get) => $get('payment_method') === 'cash')
->hidden(fn (Get $get) => $get('payment_method') === 'midtrans'),
]),
Wizard\Step::make('Selesai')
->icon('heroicon-o-check-circle')
->schema([
Placeholder::make('desc')
->label('Terima kasih')
->content('Terima kasih telah mengajukan permohonan psikotest MMPI-2. Permohonan anda akan segera diproses oleh dokter kami. Silahkan tunggu konfirmasi selanjutnya melalui email atau telepon.')
->columnSpanFull(),
Actions::make([
Action::make('submit')
->label('Selesai')
->icon('heroicon-o-check-circle')
->action(function (Livewire $livewire){
dd($livewire);
})
])->columnSpan([ 'sm' => 6, 'md' => 4, 'lg' => 3, 'xl' => 2 ])
])
])
])->statePath('data');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment