Skip to content

Commit

Permalink
marketing events.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Nov 4, 2024
1 parent 9e7b129 commit 0455cdd
Show file tree
Hide file tree
Showing 17 changed files with 727 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion packages/Webkul/Admin/src/Config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Webkul\Admin\DataGrids\Settings\Marketing;

use Illuminate\Support\Facades\DB;
use Webkul\DataGrid\DataGrid;

class EventDataGrid extends DataGrid
{
/**
* Prepare query builder.
*/
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('events')
->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'),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Webkul\Admin\Http\Controllers\Settings\Marketing;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\Marketing\EventDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Marketing\Repositories\EventRepository;

class EventController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct(protected EventRepository $eventRepository) {}

/**
* Display a listing of the marketing events.
*/
public function index(): View|JsonResponse
{
if (request()->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'),
]);
}
}
37 changes: 36 additions & 1 deletion packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -1776,7 +1809,7 @@
'title' => 'About Lead',
],

'quotes'=> [
'quotes' => [
'subject' => 'Subject',
'expired-at' => 'Expired At',
'sub-total' => 'Sub Total',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,18 @@ class="{{ request()->cookie('dark_mode') ? 'icon-light' : 'icon-dark' }} p-1.5 r
<!-- Admin profile -->
<x-admin::dropdown position="bottom-{{ in_array(app()->getLocale(), ['fa', 'ar']) ? 'left' : 'right' }}">
<x-slot:toggle>
@if (auth()->guard('user')->user()->image)
@php($user = auth()->guard('user')->user())

@if ($user->image)
<button class="flex h-9 w-9 cursor-pointer overflow-hidden rounded-full hover:opacity-80 focus:opacity-80">
<img
src="{{ auth()->guard('user')->user()->image_url }}"
class="w-full"
src="{{ $user->image_url }}"
class="h-full w-full object-cover"
/>
</button>
@else
<button class="flex h-9 w-9 cursor-pointer items-center justify-center rounded-full bg-pink-400 font-semibold leading-6 text-white">
{{ substr(auth()->guard('user')->user()->name, 0, 1) }}
{{ substr($user->name, 0, 1) }}
</button>
@endif
</x-slot>
Expand Down
Loading

0 comments on commit 0455cdd

Please sign in to comment.