From 0455cddd771c4335522e22374af0af9277d087af Mon Sep 17 00:00:00 2001 From: Suraj Kashyap Date: Mon, 4 Nov 2024 17:52:26 +0530 Subject: [PATCH] marketing events. --- composer.json | 1 + config/app.php | 1 + packages/Webkul/Admin/src/Config/menu.php | 11 +- .../Settings/Marketing/EventDataGrid.php | 105 ++++++ .../Settings/Marketing/EventController.php | 115 +++++++ .../Admin/src/Resources/lang/en/app.php | 37 ++- .../components/layouts/header/index.blade.php | 10 +- .../settings/marketing/events/index.blade.php | 309 ++++++++++++++++++ .../src/Routes/Admin/settings-routes.php | 18 + .../Webkul/Marketing/src/Contracts/Event.php | 5 + ...9_044744_create_marketing_events_table.php | 30 ++ .../Webkul/Marketing/src/Models/Event.php | 20 ++ .../Marketing/src/Models/EventProxy.php | 7 + .../Providers/MarketingServiceProvider.php | 24 ++ .../src/Providers/ModuleServiceProvider.php | 17 + .../src/Repositories/EventRepository.php | 17 + routes/breadcrumbs.php | 6 + 17 files changed, 727 insertions(+), 6 deletions(-) create mode 100644 packages/Webkul/Admin/src/DataGrids/Settings/Marketing/EventDataGrid.php create mode 100644 packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.php create mode 100644 packages/Webkul/Admin/src/Resources/views/settings/marketing/events/index.blade.php create mode 100644 packages/Webkul/Marketing/src/Contracts/Event.php create mode 100644 packages/Webkul/Marketing/src/Database/Migrations/2024_10_29_044744_create_marketing_events_table.php create mode 100644 packages/Webkul/Marketing/src/Models/Event.php create mode 100644 packages/Webkul/Marketing/src/Models/EventProxy.php create mode 100644 packages/Webkul/Marketing/src/Providers/MarketingServiceProvider.php create mode 100644 packages/Webkul/Marketing/src/Providers/ModuleServiceProvider.php create mode 100644 packages/Webkul/Marketing/src/Repositories/EventRepository.php diff --git a/composer.json b/composer.json index dd412015c..d1186fd8b 100644 --- a/composer.json +++ b/composer.json @@ -61,6 +61,7 @@ "Webkul\\Core\\": "packages/Webkul/Core/src", "Webkul\\Email\\": "packages/Webkul/Email/src", "Webkul\\EmailTemplate\\": "packages/Webkul/EmailTemplate/src", + "Webkul\\Marketing\\": "packages/Webkul/Marketing/src", "Webkul\\Installer\\": "packages/Webkul/Installer/src", "Webkul\\Lead\\": "packages/Webkul/Lead/src", "Webkul\\Product\\": "packages/Webkul/Product/src", diff --git a/config/app.php b/config/app.php index a518d9891..67d1a702c 100644 --- a/config/app.php +++ b/config/app.php @@ -208,6 +208,7 @@ Webkul\DataGrid\Providers\DataGridServiceProvider::class, Webkul\EmailTemplate\Providers\EmailTemplateServiceProvider::class, Webkul\Email\Providers\EmailServiceProvider::class, + Webkul\Marketing\Providers\MarketingServiceProvider::class, Webkul\Installer\Providers\InstallerServiceProvider::class, Webkul\Lead\Providers\LeadServiceProvider::class, Webkul\Product\Providers\ProductServiceProvider::class, diff --git a/packages/Webkul/Admin/src/Config/menu.php b/packages/Webkul/Admin/src/Config/menu.php index 1e0432d73..875abe16a 100644 --- a/packages/Webkul/Admin/src/Config/menu.php +++ b/packages/Webkul/Admin/src/Config/menu.php @@ -233,7 +233,16 @@ 'route' => 'admin.settings.email_templates.index', 'sort' => 2, 'icon-class' => 'icon-settings-mail', - ], [ + ], + [ + 'key' => 'settings.automation.events', + 'name' => 'admin::app.layouts.events', + 'info' => 'admin::app.layouts.events-info', + 'route' => 'admin.settings.marketing_events.index', + 'sort' => 2, + 'icon-class' => 'icon-settings-mail', + ], + [ 'key' => 'settings.automation.webhooks', 'name' => 'admin::app.layouts.webhooks', 'info' => 'admin::app.layouts.webhooks-info', diff --git a/packages/Webkul/Admin/src/DataGrids/Settings/Marketing/EventDataGrid.php b/packages/Webkul/Admin/src/DataGrids/Settings/Marketing/EventDataGrid.php new file mode 100644 index 000000000..636ddad1f --- /dev/null +++ b/packages/Webkul/Admin/src/DataGrids/Settings/Marketing/EventDataGrid.php @@ -0,0 +1,105 @@ +addSelect( + 'events.id', + 'events.name', + 'events.description', + 'events.date', + ); + + $this->addFilter('id', 'events.id'); + + return $queryBuilder; + } + + /** + * Add columns. + * + * @return void + */ + public function prepareColumns() + { + $this->addColumn([ + 'index' => 'id', + 'label' => trans('admin::app.settings.marketing.events.index.datagrid.id'), + 'type' => 'string', + 'sortable' => true, + 'searchable' => true, + 'filterable' => true, + ]); + + $this->addColumn([ + 'index' => 'name', + 'label' => trans('admin::app.settings.marketing.events.index.datagrid.name'), + 'type' => 'string', + 'sortable' => true, + 'searchable' => true, + 'filterable' => true, + ]); + + $this->addColumn([ + 'index' => 'description', + 'label' => trans('admin::app.settings.marketing.events.index.datagrid.description'), + 'type' => 'string', + 'sortable' => true, + ]); + + $this->addColumn([ + 'index' => 'date', + 'label' => trans('admin::app.settings.marketing.events.index.datagrid.date'), + 'type' => 'string', + 'sortable' => true, + ]); + } + + /** + * Prepare actions. + * + * @return void + */ + public function prepareActions() + { + // TODO: Implement the bouncer for this actions. + $this->addAction([ + 'index' => 'edit', + 'icon' => 'icon-edit', + 'title' => trans('admin::app.settings.marketing.events.index.datagrid.edit'), + 'method' => 'GET', + 'url' => fn ($row) => route('admin.settings.marketing_events.edit', $row->id), + ]); + + $this->addAction([ + 'index' => 'delete', + 'icon' => 'icon-delete', + 'title' => trans('admin::app.settings.marketing.events.index.datagrid.delete'), + 'method' => 'DELETE', + 'url' => fn ($row) => route('admin.settings.marketing_events.delete', $row->id), + ]); + } + + /** + * Prepare mass actions. + */ + public function prepareMassActions(): void + { + $this->addMassAction([ + 'icon' => 'icon-delete', + 'title' => trans('admin::app.settings.marketing.events.index.datagrid.delete'), + 'method' => 'POST', + 'url' => route('admin.settings.marketing_events.mass_delete'), + ]); + } +} diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.php new file mode 100644 index 000000000..96d761ddf --- /dev/null +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/Marketing/EventController.php @@ -0,0 +1,115 @@ +ajax()) { + return datagrid(EventDataGrid::class)->process(); + } + + return view('admin::settings.marketing.events.index'); + } + + /** + * Store a newly created marketing event in storage. + */ + public function store(): JsonResponse + { + $validatedData = $this->validate(request(), [ + 'name' => 'required', + 'description' => 'required', + 'date' => 'required|date|after_or_equal:today', + ]); + + Event::dispatch('settings.marketing-event.create.before'); + + $marketingEvent = $this->eventRepository->create($validatedData); + + Event::dispatch('settings.marketing-event.create.after', $marketingEvent); + + return response()->json([ + 'message' => trans('admin::app.settings.marketing-events.index.create-success'), + 'data' => $marketingEvent, + ]); + } + + /** + * Update the specified marketing event in storage. + */ + public function update(int $id): JsonResponse + { + $validatedData = $this->validate(request(), [ + 'name' => 'required', + 'description' => 'required', + 'date' => 'required|date|after_or_equal:today', + ]); + + Event::dispatch('settings.marketing-event.update.before', $id); + + $marketingEvent = $this->eventRepository->update($validatedData, $id); + + Event::dispatch('settings.marketing-event.update.after', $marketingEvent); + + return response()->json([ + 'message' => trans('admin::app.settings.marketing-events.index.update-success'), + 'data' => $marketingEvent, + ]); + } + + /** + * Remove the specified marketing event from storage. + */ + public function destroy(int $id): JsonResponse + { + Event::dispatch('settings.marketing-event.delete.before', $id); + + $this->eventRepository->delete($id); + + Event::dispatch('settings.marketing-event.delete.after', $id); + + return response()->json([ + 'message' => trans('admin::app.settings.marketing-events.index.delete-success'), + ]); + } + + /** + * Remove the specified marketing events from storage. + */ + public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse + { + $marketingEvents = $this->eventRepository->findWhereIn('id', $massDestroyRequest->input('indices')); + + dd($marketingEvents); + + foreach ($marketingEvents as $marketingEvent) { + Event::dispatch('settings.marketing-event.delete.before', $marketingEvent); + + $this->eventRepository->delete($marketingEvent->id); + + Event::dispatch('settings.marketing-event.delete.after', $marketingEvent); + } + + return response()->json([ + 'message' => trans('admin::app.settings.marketing-events.index.delete-success'), + ]); + } +} diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 29b89b357..3cbad920f 100644 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -1082,6 +1082,39 @@ ], ], + 'marketing' => [ + 'events' => [ + 'index' => [ + 'create-btn' => 'Create Marketing Event', + 'title' => 'Marketing Events', + 'create-success' => 'Marketing Event created successfully.', + 'update-success' => 'Marketing Event updated successfully.', + 'delete-success' => 'Marketing Event deleted successfully.', + 'delete-failed' => 'Marketing Event can not be deleted.', + + 'datagrid' => [ + 'delete' => 'Delete', + 'edit' => 'Edit', + 'id' => 'ID', + 'name' => 'Name', + 'description' => 'Description', + 'date' => 'Date', + ], + + 'create' => [ + 'title' => 'Create Marketing Event', + 'name' => 'Name', + 'date' => 'Date', + 'description' => 'Description', + ], + + 'edit' => [ + 'title' => 'Edit Marketing Event', + ], + ], + ], + ], + 'tags' => [ 'index' => [ 'create-btn' => 'Create Tag', @@ -1776,7 +1809,7 @@ 'title' => 'About Lead', ], - 'quotes'=> [ + 'quotes' => [ 'subject' => 'Subject', 'expired-at' => 'Expired At', 'sub-total' => 'Sub Total', @@ -1960,6 +1993,8 @@ 'email-templates' => 'Email Templates', 'email' => 'Email', 'email-templates-info' => 'Add, edit or delete email templates from CRM', + 'events' => 'Events', + 'events-info' => 'Add, edit or delete events from CRM', 'workflows' => 'Workflows', 'workflows-info' => 'Add, edit or delete workflows from CRM', 'webhooks' => 'Webhooks', diff --git a/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php b/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php index 12682d913..567d0d0a8 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/layouts/header/index.blade.php @@ -188,16 +188,18 @@ class="{{ request()->cookie('dark_mode') ? 'icon-light' : 'icon-dark' }} p-1.5 r - @if (auth()->guard('user')->user()->image) + @php($user = auth()->guard('user')->user()) + + @if ($user->image) @else @endif diff --git a/packages/Webkul/Admin/src/Resources/views/settings/marketing/events/index.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/marketing/events/index.blade.php new file mode 100644 index 000000000..575366dbb --- /dev/null +++ b/packages/Webkul/Admin/src/Resources/views/settings/marketing/events/index.blade.php @@ -0,0 +1,309 @@ + + + + @lang('admin::app.settings.marketing.events.index.title') + + +
+ +
+
+
+ {!! view_render_event('admin.settings.marketing-events.index.breadcrumbs.before') !!} + + + + + {!! view_render_event('admin.settings.marketing-events.index.breadcrumbs.after') !!} +
+ +
+ @lang('admin::app.settings.marketing.events.index.title') +
+
+ +
+ +
+ {!! view_render_event('admin.settings.marketing-events.index.breadcrumbs.after') !!} + + + + {!! view_render_event('admin.settings.marketing-events.index.create_button.after') !!} +
+
+
+ + + + +
+ + @pushOnce('scripts') + + + + @endPushOnce +
diff --git a/packages/Webkul/Admin/src/Routes/Admin/settings-routes.php b/packages/Webkul/Admin/src/Routes/Admin/settings-routes.php index 972c30544..1550bc315 100644 --- a/packages/Webkul/Admin/src/Routes/Admin/settings-routes.php +++ b/packages/Webkul/Admin/src/Routes/Admin/settings-routes.php @@ -5,6 +5,7 @@ use Webkul\Admin\Http\Controllers\Settings\EmailTemplateController; use Webkul\Admin\Http\Controllers\Settings\GroupController; use Webkul\Admin\Http\Controllers\Settings\LocationController; +use Webkul\Admin\Http\Controllers\Settings\Marketing\EventController; use Webkul\Admin\Http\Controllers\Settings\PipelineController; use Webkul\Admin\Http\Controllers\Settings\RoleController; use Webkul\Admin\Http\Controllers\Settings\SettingController; @@ -289,4 +290,21 @@ Route::delete('{id}', 'destroy')->name('admin.settings.email_templates.delete'); }); + + /** + * Events Routes. + */ + Route::controller(EventController::class)->prefix('events')->group(function () { + Route::get('', 'index')->name('admin.settings.marketing_events.index'); + + Route::post('create', 'store')->name('admin.settings.marketing_events.store'); + + Route::get('edit/{id?}', 'edit')->name('admin.settings.marketing_events.edit'); + + Route::put('edit/{id}', 'update')->name('admin.settings.marketing_events.update'); + + Route::delete('{id}', 'destroy')->name('admin.settings.marketing_events.delete'); + + Route::post('mass-destroy', 'massDestroy')->name('admin.settings.marketing_events.mass_delete'); + }); }); diff --git a/packages/Webkul/Marketing/src/Contracts/Event.php b/packages/Webkul/Marketing/src/Contracts/Event.php new file mode 100644 index 000000000..4c97af079 --- /dev/null +++ b/packages/Webkul/Marketing/src/Contracts/Event.php @@ -0,0 +1,5 @@ +id(); + $table->string('name'); + $table->string('description'); + $table->date('date'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('events'); + } +}; diff --git a/packages/Webkul/Marketing/src/Models/Event.php b/packages/Webkul/Marketing/src/Models/Event.php new file mode 100644 index 000000000..525930c2b --- /dev/null +++ b/packages/Webkul/Marketing/src/Models/Event.php @@ -0,0 +1,20 @@ +loadMigrationsFrom(__DIR__.'/../Database/Migrations'); + } + + /** + * Register services. + */ + public function register(): void + { + $this->app->register(ModuleServiceProvider::class); + } +} diff --git a/packages/Webkul/Marketing/src/Providers/ModuleServiceProvider.php b/packages/Webkul/Marketing/src/Providers/ModuleServiceProvider.php new file mode 100644 index 000000000..a625aa0c4 --- /dev/null +++ b/packages/Webkul/Marketing/src/Providers/ModuleServiceProvider.php @@ -0,0 +1,17 @@ +push(trans('admin::app.settings.email-template.edit.title'), route('admin.settings.email_templates.edit', $emailTemplate->id)); }); +// Settings > Marketing Events +Breadcrumbs::for('settings.marketing_events', function (BreadcrumbTrail $trail) { + $trail->parent('settings'); + $trail->push(trans('admin::app.settings.marketing.events.index.title'), route('admin.settings.marketing_events.index')); +}); + // Settings > Workflows Breadcrumbs::for('settings.workflows', function (BreadcrumbTrail $trail) { $trail->parent('settings');