Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webform create and edit page and setup vite. #1304

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php

namespace Webkul\Admin\Http\Controllers\Settings;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Contact\Repositories\PersonRepository;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Lead\Repositories\PipelineRepository;
use Webkul\Lead\Repositories\SourceRepository;
use Webkul\Lead\Repositories\TypeRepository;
use Webkul\WebForm\DataGrids\WebFormDataGrid;
use Webkul\WebForm\Repositories\WebFormRepository;

class WebFormController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct(
protected AttributeRepository $attributeRepository,
protected WebFormRepository $webFormRepository,
protected PersonRepository $personRepository,
protected LeadRepository $leadRepository,
protected PipelineRepository $pipelineRepository,
protected SourceRepository $sourceRepository,
protected TypeRepository $typeRepository
) {}

/**
* Display a listing of the email template.
*/
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return datagrid(WebFormDataGrid::class)->process();
}

return view('admin::settings.web-forms.index');
}

/**
* Show the form for creating a new resource.
*/
public function create(): View
{
$tempAttributes = $this->attributeRepository->findWhereIn('entity_type', ['persons', 'leads']);

$attributes = [];

foreach ($tempAttributes as $attribute) {
if ($attribute->entity_type == 'persons'
&& (
$attribute->code == 'name'
|| $attribute->code == 'emails'
|| $attribute->code == 'contact_numbers'
)
) {
$attributes['default'][] = $attribute;
} else {
$attributes['other'][] = $attribute;
}
}

return view('admin::settings.web-forms.create', compact('attributes'));
}

/**
* Store a newly created email templates in storage.
*/
public function store(): RedirectResponse
{
$this->validate(request(), [
'title' => 'required',
'submit_button_label' => 'required',
'submit_success_action' => 'required',
'submit_success_content' => 'required',
]);

Event::dispatch('settings.web_forms.create.before');

$data = request()->all();

$data['create_lead'] = isset($data['create_lead']) ? 1 : 0;

$webForm = $this->webFormRepository->create($data);

Event::dispatch('settings.web_forms.create.after', $webForm);

session()->flash('success', trans('admin::app.settings.webforms.index.create-success'));

return redirect()->route('admin.settings.web_forms.index');
}

/**
* Show the form for editing the specified email template.
*/
public function edit(int $id): View
{
$webForm = $this->webFormRepository->findOrFail($id);

$attributes = $this->attributeRepository->findWhere([
['entity_type', 'IN', ['persons', 'leads']],
['id', 'NOTIN', $webForm->attributes()->pluck('attribute_id')->toArray()],
]);

return view('admin::settings.web-forms.edit', compact('webForm', 'attributes'));
}

/**
* Update the specified email template in storage.
*/
public function update(int $id): RedirectResponse
{
$this->validate(request(), [
'title' => 'required',
'submit_button_label' => 'required',
'submit_success_action' => 'required',
'submit_success_content' => 'required',
]);

Event::dispatch('settings.web_forms.update.before', $id);

$data = request()->all();

$data['create_lead'] = isset($data['create_lead']) ? 1 : 0;

$webForm = $this->webFormRepository->update($data, $id);

Event::dispatch('settings.web_forms.update.after', $webForm);

session()->flash('success', trans('admin::app.settings.webforms.index.update-success'));

return redirect()->route('admin.settings.web_forms.index');
}

/**
* Remove the specified email template from storage.
*/
public function destroy(int $id): JsonResponse
{
$webForm = $this->webFormRepository->findOrFail($id);

try {
Event::dispatch('settings.web_forms.delete.before', $id);

$webForm->delete($id);

Event::dispatch('settings.web_forms.delete.after', $id);

return response()->json([
'message' => trans('admin::app.settings.webforms.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.webforms.index.delete-failed'),
], 400);
}
}
}
6 changes: 4 additions & 2 deletions packages/Webkul/Admin/src/Http/helpers.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

use Webkul\Admin\Vite as AdminVite;

if (! function_exists('bouncer')) {
function bouncer()
{
return app()->make('bouncer');
}
}

function vite()
function admin_vite(): AdminVite
{
return app(\Webkul\Core\Vite::class);
return app(AdminVite::class);
}
2 changes: 1 addition & 1 deletion packages/Webkul/Admin/src/Resources/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
}

.secondary-button {
@apply flex cursor-pointer place-content-center items-center gap-x-1 whitespace-nowrap rounded-md border-2 border-blue-600 bg-white px-3 py-1.5 font-semibold text-blue-600 transition-all hover:bg-[#eff6ff61] focus:bg-[#eff6ff61] dark:border-gray-400 dark:bg-gray-800 dark:text-white dark:hover:opacity-80;
@apply flex cursor-pointer place-content-center items-center gap-x-1 whitespace-nowrap rounded-md border-2 border-brandColor bg-white px-3 py-1.5 font-semibold text-brandColor transition-all hover:bg-[#eff6ff61] focus:bg-[#eff6ff61] dark:border-gray-400 dark:bg-gray-800 dark:text-white dark:hover:opacity-80;
}

.transparent-button {
Expand Down
2 changes: 2 additions & 0 deletions packages/Webkul/Admin/src/Resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ import Emitter from "./plugins/emitter";
import Flatpickr from "./plugins/flatpickr";
import VeeValidate from "./plugins/vee-validate";
import CreateElement from "./plugins/createElement";
import Draggable from "./plugins/draggable";
import VueCal from "./plugins/vue-cal";

[
Axios,
Emitter,
CreateElement,
Draggable,
Flatpickr,
VeeValidate,
VueCal,
Expand Down
10 changes: 10 additions & 0 deletions packages/Webkul/Admin/src/Resources/assets/js/plugins/draggable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Draggable from 'vuedraggable';

export default {
install: (app) => {
/**
* Global component registration;
*/
app.component("draggable", Draggable);
},
};
70 changes: 70 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,76 @@
],
],

'webforms' => [
'index' => [
'title' => 'Webforms',
'create-btn' => 'Create Webform',
'create-success' => 'Webform created successfully.',
'update-success' => 'Webform updated successfully.',
'delete-success' => 'Webform deleted successfully.',
'delete-failed' => 'Webform can not be deleted.',
'datagrid' => [
'id' => 'ID',
'title' => 'Title',
'edit' => 'Edit',
'delete' => 'Delete',
],
],

'create' => [
'title' => 'Create Webform',
'save-btn' => 'Save Webform',
'submit-success-action' => 'Submit Success Action',
'general' => 'General',
'create-lead' => 'Create Lead',
'customize-webform' => 'Customize Webform',
'customize-webform-info' => 'Customize your web form with element colors of your choosing.',
'backgroud-color' => 'Backgroud Color',
'form-backgroud-color' => 'Form Backgroud Color',
'form-title-color' => 'Form Title Color',
'form-submit-btn-color' => 'Form Submit Button Color',
'attribute-label-color' => 'Attribute Label Color',
'attributes' => 'Attributes',
'attributes-info' => 'Add custom attributes to the form.',
'add-attribute-btn' => 'Add Attribute Button',
'description' => 'Description',
'submit-button-label' => 'Submit Button Label',
'form-background-color' => 'Form Backgroud Color',
'form-submit-button-color' => 'Form Submit Button Color',
'display-custom-message' => 'Display custom message',
],

'edit' => [
'title' => 'Edit Webform',
'embed' => 'Embded',
'preview' => 'Preview',
'save-btn' => 'Save Webform',
'submit-success-action' => 'Submit Success Action',
'general' => 'General',
'create-lead' => 'Create Lead',
'customize-webform' => 'Customize Webform',
'customize-webform-info' => 'Customize your web form with element colors of your choosing.',
'backgroud-color' => 'Backgroud Color',
'form-backgroud-color' => 'Form Backgroud Color',
'form-title-color' => 'Form Title Color',
'form-background-color' => 'Form Backgroud Color',
'form-submit-btn-color' => 'Form Submit Button Color',
'attribute-label-color' => 'Attribute Label Color',
'attributes' => 'Attributes',
'attributes-info' => 'Add custom attributes to the form.',
'add-attribute-btn' => 'Add Attribute Button',
'description' => 'Description',
'submit-button-label' => 'Submit Button Label',
'redirect-to-url' => 'Redirect To URL',
'copied' => 'Copied',
'copy' => 'Copy',
'public-url' => 'Public URL',
'code-snippet' => 'Code Snippet',
'form-submit-button-color' => 'Form Submit Button Color',
'display-custom-message' => 'Display custom message',
],
],

'email-template' => [
'index' => [
'create-btn' => 'Create Email Template',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@stack('meta')

{{
vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js'])
admin_vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js'])
}}

<link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="{{ route('admin.dashboard.index') }}">
<img
class="h-10"
src="{{ vite()->asset('images/logo.svg') }}"
src="{{ admin_vite()->asset('images/logo.svg') }}"
alt="{{ config('app.name') }}"
/>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class="{{ request()->cookie('dark_mode') ? 'dark' : '' }}"
@stack('meta')

{{
vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js'])
admin_vite()->set(['src/Resources/assets/css/app.css', 'src/Resources/assets/js/app.js'])
}}

<link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class="h-10 w-[110px]"
@else
<img
class="w-max"
src="{{ vite()->asset('images/logo.svg') }}"
src="{{ admin_vite()->asset('images/logo.svg') }}"
alt="{{ config('app.name') }}"
/>
@endif
Expand Down
Loading
Loading