-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
994 additions
and
492 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use BenSampo\Enum\Enum; | ||
|
||
final class CustomFormStatus extends Enum | ||
{ | ||
const DRAFT = 'draft'; | ||
|
||
const ACTIVE = 'active'; | ||
|
||
const DISABLED = 'disabled'; | ||
|
||
const ARCHIVED = 'archived'; | ||
|
||
public function toArray(): mixed | ||
{ | ||
return [ | ||
'key' => $this->key, | ||
'value' => $this->value, | ||
]; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Enums\CustomFormStatus; | ||
use App\Models\CustomForm; | ||
use BenSampo\Enum\Rules\EnumValue; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class CreateCustomFormRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return Gate::allows('create', CustomForm::class); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
$inputTypes = config('constants.custom_form_input_types'); | ||
|
||
return [ | ||
'title' => 'required|string|max:255', | ||
'slug' => 'required|alpha_dash|max:255|unique:custom_forms,slug', | ||
'description' => 'nullable|string|max:50000', | ||
'status' => ['required', new EnumValue(CustomFormStatus::class)], | ||
'can_create_submission' => 'required|string|in:anyone,auth,staff', | ||
'require_restricted_permission_to_view_submission' => 'required|boolean', | ||
'is_notify_staff_on_submission' => 'required|boolean', | ||
'fields' => 'required|array', | ||
'fields.*.type' => 'required|string|in:'.implode(',', $inputTypes), | ||
'fields.*.label' => 'required|string|max:255', | ||
'fields.*.name' => 'required|string|alpha_dash|max:100|distinct:ignore_case', | ||
'fields.*.placeholder' => 'sometimes|nullable|string|max:255', | ||
'fields.*.help' => 'sometimes|nullable|string|max:255', | ||
'fields.*.validation' => 'sometimes|nullable|string|max:255', | ||
'fields.*.options' => 'sometimes|nullable|string', | ||
]; | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Enums\CustomFormStatus; | ||
use BenSampo\Enum\Rules\EnumValue; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rule; | ||
|
||
class UpdateCustomFormRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
$inputTypes = config('constants.custom_form_input_types'); | ||
|
||
return [ | ||
'title' => 'required|string|max:255', | ||
'slug' => [ | ||
'required', | ||
'alpha_dash', | ||
'max:255', | ||
Rule::unique('custom_forms')->ignore($this->route('customForm')), | ||
], | ||
'description' => 'nullable|string|max:50000', | ||
'status' => ['required', new EnumValue(CustomFormStatus::class)], | ||
'can_create_submission' => 'required|string|in:anyone,auth,staff', | ||
'require_restricted_permission_to_view_submission' => 'required|boolean', | ||
'is_notify_staff_on_submission' => 'required|boolean', | ||
'fields' => 'required|array', | ||
'fields.*.type' => 'required|string|in:'.implode(',', $inputTypes), | ||
'fields.*.label' => 'required|string|max:255', | ||
'fields.*.name' => 'required|string|alpha_dash|max:100|distinct:ignore_case', | ||
'fields.*.placeholder' => 'sometimes|nullable|string|max:255', | ||
'fields.*.help' => 'sometimes|nullable|string|max:255', | ||
'fields.*.validation' => 'sometimes|nullable|string|max:255', | ||
'fields.*.options' => 'sometimes|nullable|string', | ||
]; | ||
} | ||
} |
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,30 @@ | ||
export function useFormKit() { | ||
const generateSchemaFromFieldsArray = (fields) => { | ||
const generated = fields.map((field) => { | ||
let f = { | ||
$formkit: field.type == 'multiselect' ? 'select' : field.type, | ||
label: field.label, | ||
name: | ||
field.name ?? field.label.toLowerCase().replace(/ /g, '_'), | ||
help: field.help ?? undefined, | ||
validation: field.validation ?? undefined, | ||
placeholder: field.placeholder ?? undefined, | ||
multiple: field.type == 'multiselect' ? true : undefined, | ||
}; | ||
|
||
if ( | ||
field.type === 'select' || | ||
field.type === 'multiselect' || | ||
field.type === 'radio' | ||
) { | ||
f.options = field.options?.split(',') ?? []; | ||
} | ||
return f; | ||
}); | ||
return generated; | ||
}; | ||
|
||
return { | ||
generateSchemaFromFieldsArray, | ||
}; | ||
} |
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
Oops, something went wrong.