add nova wizard

This commit is contained in:
2023-11-24 21:19:50 +05:00
parent 0898dbc73f
commit 392136dc9b
6 changed files with 194 additions and 3 deletions

View File

@@ -190,7 +190,7 @@ class LoanOrder extends Resource
// $table->text('passport_two');
// $table->text('passport_three');
// $table->text('passport_four');
// $table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
// $table->foreignId('user_id')->constrained('users')->restrictOnDelete();
// $table->string('status')->index();

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Nova\Wizards;
use App\Models\User;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Textarea;
use Wdelfuego\NovaWizard\AbstractWizard;
class AddUserWizard extends AbstractWizard
{
public function wizardViewData(): array
{
return [
'steps' => [
[
'title' => 'Step 1/2',
'fields' => [
Text::make(__('Username'), 'username'),
Text::make(__('Text field'), 'myText'),
Textarea::make(__('Longer text'), 'myLongerText')
->help("You can use Help texts on Nova fields like you're used to"),
Number::make(__('Some number'), 'myNumber')
->rules('required')
->withMeta(['value' => 60])
->min(1)
->step(1),
],
],
[
'title' => 'Step 2/2',
'fields' => [
Text::make(__('Text field 2'), 'myText2'),
Textarea::make(__('Longer text 2'), 'myLongerText2')
->help("You can use Help texts on Nova fields like you're used to"),
Number::make(__('Some number 2'), 'myNumber2')
->rules('required')
->withMeta(['value' => 60])
->min(1)
->step(1),
],
],
[
'title' => 'Step 2/2',
'fields' => [
Text::make(__('Text field 2'), 'myText2'),
Textarea::make(__('Longer text 2'), 'myLongerText2')
->help("You can use Help texts on Nova fields like you're used to"),
Number::make(__('Some number 2'), 'myNumber2')
->rules('required')
->withMeta(['value' => 60])
->min(1)
->step(1),
],
],
],
];
}
public function onSubmit($formData, &$context): bool
{
//
// When this method gets called, a valid and complete wizard was submitted.
//
// $formData is an array that contains the data submitted by the user.
//
// $context is an empty array that you can store arbitrary info in;
// it will be passed to the next method so you can use it
// to display specific context info to the user on success.
// Parse submitted wizard data somehow
$user = User::create(['name' => $formData['username']]);
$context['newUserId'] = $user->id;
// Return true at the end of this method to indicate success
return true;
// Or return false if the data can not be parsed successfully;
// the user will then stay in the form view and have a chance
// to revise the data before resubmitting.
}
public function successViewData($context): array
{
return [
'message' => 'Successfully created user with id: '.$context['newUserId'],
];
}
}

View File

@@ -21,6 +21,7 @@ use Laravel\Nova\Menu\MenuItem;
use Laravel\Nova\Menu\MenuSection;
use Laravel\Nova\Nova;
use Laravel\Nova\NovaApplicationServiceProvider;
use Wdelfuego\NovaWizard\NovaWizard;
class NovaServiceProvider extends NovaApplicationServiceProvider
{
@@ -83,6 +84,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
LocaleSwitcher::make()
->setLocales(config('app.locales'))
->onSwitchLocale(NovaRepo::localeSwitcherSave()),
// new NovaWizard('add-user'),
];
}
@@ -105,6 +107,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
MenuSection::make(__('Orders'), [
MenuItem::resource(LoanOrder::class),
// MenuItem::link('Add a user', NovaWizard::pathToWizard('add-user'))
])->icon('collection')->collapsable(),
MenuSection::make(__('System'), [

View File

@@ -16,7 +16,8 @@
"outl1ne/nova-translatable": "^2.2",
"spatie/laravel-permission": "^6.1",
"spatie/laravel-translatable": "^6.5",
"trin4ik/nova-switcher": "^0.4.0"
"trin4ik/nova-switcher": "^0.4.0",
"wdelfuego/nova-wizard": "^1.0"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

53
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "77a24bc6798fc44d2104306518b27e22",
"content-hash": "e54517769c07296164429fd898ff3555",
"packages": [
{
"name": "brick/math",
@@ -7071,6 +7071,57 @@
],
"time": "2022-03-08T17:03:00+00:00"
},
{
"name": "wdelfuego/nova-wizard",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/wdelfuego/nova-wizard.git",
"reference": "4e8879415a417f10554a69e3214acd2fb8599c1f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wdelfuego/nova-wizard/zipball/4e8879415a417f10554a69e3214acd2fb8599c1f",
"reference": "4e8879415a417f10554a69e3214acd2fb8599c1f",
"shasum": ""
},
"require": {
"laravel/nova": "^4.0",
"php": "^7.3|^8.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Wdelfuego\\NovaWizard\\ToolServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Wdelfuego\\NovaWizard\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"AGPL-3.0-or-later",
"proprietary"
],
"description": "A tool to create wizards in Nova 4.",
"keywords": [
"form",
"laravel",
"multi step",
"multistep",
"nova",
"wizard"
],
"support": {
"issues": "https://github.com/wdelfuego/nova-wizard/issues",
"source": "https://github.com/wdelfuego/nova-wizard/tree/v1.0.1"
},
"time": "2023-10-17T13:18:08+00:00"
},
{
"name": "webmozart/assert",
"version": "1.11.0",

46
config/nova-wizard.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
use App\Nova\Wizards\AddUserWizard;
/*
* © Copyright 2023 · Willem Vervuurt, Studio Delfuego
*
* You can modify, use and distribute this package under one of two licenses:
* 1. GNU AGPLv3
* 2. A perpetual, non-revocable and 100% free (as in beer) do-what-you-want
* license that allows both non-commercial and commercial use, under conditions.
* See LICENSE.md for details.
*
* (it boils down to: do what you want as long as you're building and/or
* using wizards, but don't embed this package or a modified version
* of it in free or paid-for software libraries and packages aimed at developers).
*/
return [
'add-user' => [
/*
* The class of the Nova Wizard.
Don't forget to add the proper use statement above.
This key is required.
*/
'class' => AddUserWizard::class,
/*
* URI for this wizard (will be appended to the Nova path, /nova by default)
This key is required.
*/
'uri' => 'wizard/add-user',
/*
* Browser window/tab title for this Nova Wizard.
This key is optional.
If you remove it or set it to an empty string, the dynamic title displayed above
the wizard view will be used as window/tab title in the browser.
*/
'windowTitle' => 'Add User',
],
];