added support ticket and added more stat widgets

This commit is contained in:
Gitea
2025-05-17 05:11:29 +05:30
parent f30d7fa096
commit 175a7203f3
19 changed files with 975 additions and 6 deletions

View File

@@ -0,0 +1,220 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\TicketResource\Pages;
use App\Filament\Resources\TicketResource\RelationManagers;
use App\Models\Ticket;
use App\Models\TicketResponse;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\HtmlString;
class TicketResource extends Resource
{
protected static ?string $model = Ticket::class;
protected static ?string $navigationIcon = 'heroicon-o-ticket';
protected static ?string $navigationGroup = 'Support';
public static function form(Form $form): Form
{
return $form
->schema([
Select::make('user_id')
->relationship('user', 'name')
->searchable()
->preload()
->required(),
Select::make('status')
->label('Status')
->options([
'open' => 'Open',
'pending' => 'In Progress',
'closed' => 'Closed',
])
->default('open')
->required(),
TextInput::make('subject')
->label('Subject')
->required()
->maxLength(255)
->columnSpanFull(),
TextArea::make('message')
->label('Message')
->required()
->rows(7)
->maxLength(2000)
->columnSpanFull(),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([
TextColumn::make('ticket_id')
->label('Ticket ID')
->sortable(),
TextColumn::make('user.name'),
TextColumn::make('subject')
->limit(50)
->label('Subject'),
BadgeColumn::make('status')
->colors([
'success' => fn ($state) => $state === 'open',
'warning' => fn ($state) => $state === 'pending',
'danger' => fn ($state) => $state === 'closed',
])
->sortable(),
TextColumn::make('created_at')
->label('Created At')
->dateTime('F d, Y • h:i A')->sortable(),
TextColumn::make('last_response_at')
->label('Last Response')
->sortable()
->formatStateUsing(fn ($state) => $state?->diffForHumans()),
])
->filters([
SelectFilter::make('status')
->label('Status')
->options([
'open' => 'Open',
'pending' => 'In Progress',
'closed' => 'Closed',
])
->attribute('status'),
Filter::make('created_at')
->form([
DatePicker::make('created_from')->label('Created From'),
DatePicker::make('created_until')->label('Created Until'),
])
->query(function ($query, array $data) {
return $query
->when($data['created_from'], fn ($query, $date) => $query->whereDate('created_at', '>=', $date))
->when($data['created_until'], fn ($query, $date) => $query->whereDate('created_at', '<=', $date));
}),
])
// ->actions([
// Tables\Actions\EditAction::make(),
// ])
->actions([
Action::make('view')
->label('View & Respond')
->icon('heroicon-o-eye')
->form(function (Ticket $ticket): array {
return [
TextArea::make('response')
->label('Your Response')
->required()
->rows(7)
->placeholder('Type your response here...'),
Select::make('status')
->label('Ticket Status')
->options([
'open' => 'Open',
'pending' => 'In Progress',
'closed' => 'Closed',
])
->default($ticket->status === 'open' ? 'pending' : $ticket->status)
->required(),
];
})
->modalContent(function (Ticket $ticket) {
$html = '<div class="space-y-3 mb-3 text-sm">';
// Ticket Subject & Message
$html .= '<div class="bg-gray-100 dark:bg-gray-900 border p-2 rounded-md">';
$html .= '<h6 class="xs font-semibold text-gray-800 dark:text-gray-100">Subject: ' . e($ticket->subject) . '</h6>';
$html .= '<p class="mt-1 text-gray-700 dark:text-gray-300">Message: ' . nl2br(e($ticket->message)) . '</p>';
$html .= '</div>';
// Responses Section
$html .= '<h6 class="text-xs font-bold text-gray-700 dark:text-gray-200 mt-2">Previous Responses</h6>';
foreach ($ticket->responses as $response) {
$html .= '<div class="rounded-md border p-2 bg-gray-50 dark:bg-gray-800">';
$html .= '<div class="text-xs text-gray-600 dark:text-gray-300">';
$html .= '<strong>' . e($response->user->name) . '</strong>';
$html .= '<span class="ml-2 text-[11px] text-gray-500">' . e($response->created_at->diffForHumans()) . '</span>';
$html .= '</div>';
$html .= '<p class="mt-1 text-gray-800 dark:text-gray-100">' . nl2br(e($response->response)) . '</p>';
$html .= '</div>';
}
if ($ticket->responses->isEmpty()) {
$html .= '<p class="text-xs text-gray-500">No responses yet.</p>';
}
$html .= '</div>';
return new \Illuminate\Support\HtmlString($html);
})
->action(function (array $data, Ticket $ticket) {
TicketResponse::create([
'ticket_id' => $ticket->id,
'user_id' => auth()->id(),
'response' => $data['response'],
]);
// Update ticket status and last response time
$ticket->update([
'status' => $data['status'],
'last_response_at' => now(),
]);
// Send success notification
Notification::make()
->title('Response sent successfully!')
->success()
->send();
})
->modalHeading('View & Respond to Ticket')
->modalSubmitActionLabel('Send Reply'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
RelationManagers\ResponsesRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListTickets::route('/'),
'create' => Pages\CreateTicket::route('/create'),
'edit' => Pages\EditTicket::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\TicketResource\Pages;
use App\Filament\Resources\TicketResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateTicket extends CreateRecord
{
protected static string $resource = TicketResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\TicketResource\Pages;
use App\Filament\Resources\TicketResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditTicket extends EditRecord
{
protected static string $resource = TicketResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\TicketResource\Pages;
use App\Filament\Resources\TicketResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListTickets extends ListRecords
{
protected static string $resource = TicketResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Filament\Resources\TicketResource\RelationManagers;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class ResponsesRelationManager extends RelationManager
{
protected static string $relationship = 'responses';
public function form(Form $form): Form
{
return $form
->schema([
Select::make('user_id')
->relationship('user', 'name')
->searchable()
->preload()
->default(1)
->required()
->columnSpanFull(),
Textarea::make('response')
->required()
->rows(7)
->maxLength(255)
->columnSpanFull(),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('response')
->columns([
TextColumn::make('user.name'),
TextColumn::make('ip_address'),
TextColumn::make('response'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -4,6 +4,8 @@ namespace App\Filament\Widgets;
use App\Models\Log;
use App\Models\Meta;
use App\Models\PremiumEmail;
use App\Models\Ticket;
use App\Models\User;
use DB;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
@@ -15,10 +17,14 @@ class StatsOverview extends BaseWidget
{
return [
Stat::make('Total Users', $this->getUser()),
Stat::make('Customers', $this->getCustomerCount()),
Stat::make('Paid Users', $this->getUserPaid()),
Stat::make('Logs Count', $this->getLogsCount()),
Stat::make('Total Mailbox', $this->getTotalMailbox()),
Stat::make('Emails Received', $this->getTotalEmailsReceived()),
Stat::make('Emails Stored', $this->getStoreEmailsCount()),
Stat::make('Open Tickets', $this->getOpenTicketsCount()),
Stat::make('Closed Tickets', $this->getClosedTicketsCount()),
];
}
private function getUser(): int
@@ -44,4 +50,22 @@ class StatsOverview extends BaseWidget
{
return Meta::select('value')->where(['key' => 'messages_received'])->first()->value;
}
private function getCustomerCount(): int
{
return User::whereNotNull('stripe_id')->count();
}
private function getStoreEmailsCount(): int
{
return PremiumEmail::all()->count();
}
private function getOpenTicketsCount(): int
{
return Ticket::whereIn('status', ['open', 'pending'])->count();
}
private function getClosedTicketsCount(): int
{
return Ticket::whereIn('status', ['closed'])->count();
}
}

View File

@@ -0,0 +1,149 @@
<?php
namespace App\Livewire\Dashboard;
use App\Models\Ticket;
use App\Models\TicketResponse;
use Livewire\Component;
use Request;
use Str;
class Support extends Component
{
public $tickets = [];
public $subject;
public $message;
public $response;
public $list = false;
public $open = 0;
public $closed = 0;
public function store()
{
$this->validate([
'subject' => 'required|string|max:255',
'message' => 'required|string',
]);
try {
$ticket = Ticket::create([
'user_id' => auth()->id(),
'ticket_id' => strtoupper(Str::random(6)),
'subject' => $this->subject,
'message' => $this->message,
'ip_address' => $this->getClientIp(),
'last_response_at' => now(),
]);
$this->dispatch('showAlert', ['type' => 'success', 'message' => 'Your ticket has been created successfully!']);
$this->dispatch('closeModal');
$this->reset(['subject','message']);
$this->tickets = Ticket::with('responses')
->where('user_id', auth()->id())
->get();
} catch (\Exception $exception) {
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Something went wrong!']);
}
}
public function reply($ticket_id)
{
$this->validate([
'response' => 'required|string',
]);
try {
if (!is_numeric($ticket_id)) {
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Invalid ticket ID.']);
return;
}
$ticket = Ticket::find($ticket_id);
if (!$ticket) {
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Ticket not found.']);
return;
}
TicketResponse::create([
'ticket_id' => $ticket_id,
'user_id' => auth()->id(),
'response' => $this->response,
'ip_address' => $this->getClientIp(),
]);
$ticket->last_response_at = now();
$ticket->save();
$this->dispatch('showAlert', ['type' => 'success', 'message' => 'Reply sent successfully!']);
$this->reset(['response']);
$this->tickets = Ticket::with('responses')
->where('user_id', auth()->id())
->get();
} catch (\Exception $exception) {
session()->flash('error', 'Something went wrong!');
}
}
public function close($ticket_id)
{
if (!is_numeric($ticket_id)) {
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Invalid ticket ID.']);
return;
}
$ticket = Ticket::find($ticket_id);
if (!$ticket) {
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'Ticket not found.']);
return;
}
$ticket->status = 'closed';
$ticket->save();
$this->tickets = Ticket::with('responses')
->where('user_id', auth()->id())
->get();
$this->updateTicketCounts();
$this->dispatch('showAlert', ['type' => 'error', 'message' => 'This ticket has been closed!']);
}
public function mount()
{
$this->tickets = Ticket::with('responses')
->where('user_id', auth()->id())
->get();
$this->updateTicketCounts();
}
public function updateTicketCounts()
{
$this->open = $this->tickets->filter(function ($ticket) {
return in_array($ticket->status, ['open', 'pending']);
})->count();
$this->closed = $this->tickets->filter(function ($ticket) {
return $ticket->status === 'closed';
})->count();
}
protected function getClientIp()
{
// Cloudflare or other proxies may send the original client IP in X-Forwarded-For header
$ip = Request::header('X-Forwarded-For');
// X-Forwarded-For can contain a comma-separated list of IPs, so we need to get the first one
if ($ip) {
return explode(',', $ip)[0]; // Get the first IP in the list
}
// Fallback to the real IP if no X-Forwarded-For header
return Request::ip();
}
public function render()
{
return view('livewire.dashboard.support')->layout('components.layouts.dashboard');
}
}

57
app/Models/Ticket.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Ticket extends Model
{
use HasFactory;
protected $fillable = [
'user_id', 'ticket_id', 'subject', 'message', 'status', 'last_response_at', 'ip_address'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function responses()
{
return $this->hasMany(TicketResponse::class);
}
protected $casts = [
'created_at' => 'datetime', // Ensures created_at is a Carbon instance
'updated_at' => 'datetime', // Ensures updated_at is a Carbon instance
'last_response_at' => 'datetime', // Cast last_response_at to Carbon instance
];
public static function autoClose(): bool
{
try {
$tickets = Ticket::where('status', 'pending')
->where('last_response_at', '<', now()->subDays(3))
->get();
if (count($tickets) > 0) {
foreach ($tickets as $ticket) {
$ticket->status = 'closed';
$ticket->save();
TicketResponse::create([
'ticket_id' => $ticket->id,
'user_id' => 1,
'response' => 'This ticket has been auto-closed due to inactivity.',
]);
}
}
return true;
} catch (\Exception $e) {
return false;
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TicketResponse extends Model
{
use HasFactory;
protected $fillable = [
'ticket_id', 'user_id', 'response', 'ip_address'
];
public function ticket()
{
return $this->belongsTo(Ticket::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@@ -6,6 +6,7 @@ namespace App\Models;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
@@ -63,4 +64,9 @@ class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
return str_ends_with($this->email, '@zemail.me') && $this->level === 9 && $this->hasVerifiedEmail();
}
public function tickets(): HasMany
{
return $this->hasMany(Ticket::class);
}
}

24
closeTicket.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
// Adjust this path if your file location is different
require __DIR__ . '/vendor/autoload.php';
// Bootstrap the Laravel application
$app = require_once __DIR__ . '/bootstrap/app.php';
// Make the Console Kernel instance
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
try {
// Run the Artisan command 'ping'
$exitCode = $kernel->call('closeTicket');
// Get the output of the command
$output = $kernel->output();
echo "Artisan command 'closeTicket' executed successfully. Exit code: $exitCode\n";
echo "Output:\n$output";
} catch (\Exception $e) {
echo "Error running Artisan command: " . $e->getMessage();
}

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tickets', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('ticket_id', 6)->unique();
$table->string('subject');
$table->text('message');
$table->enum('status', ['open', 'closed', 'pending'])->default('open');
$table->ipAddress()->nullable();
$table->timestamp('last_response_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tickets');
}
};

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('ticket_responses', function (Blueprint $table) {
$table->id();
$table->foreignId('ticket_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->text('response');
$table->ipAddress()->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ticket_responses');
}
};

View File

@@ -40,7 +40,7 @@
//['label' => '10 Minute Mail', 'route' => 'dashboard.10minute'],
['label' => 'Bulk Email Generator', 'route' => 'dashboard.bulk'],
['label' => 'Bulk Gmail Generator', 'route' => 'dashboard.bulkGmail'],
//['label' => 'Compose Email', 'route' => 'dashboard.compose'],
['label' => 'Support Ticket', 'route' => 'dashboard.support'],
];
$currentRoute = Route::currentRouteName();

View File

@@ -95,7 +95,7 @@
@endif
@if (session()->has('error'))
<div class="mt-4 text-green-700">
<div class="mt-4 app-primary">
{{ session('error') }}
</div>
@endif

View File

@@ -0,0 +1,199 @@
@section('title'){{ __('Support Ticket') }}@endsection
<span>
<div class="flex h-full w-full flex-1 flex-col gap-4 rounded-xl">
<div class="grid auto-rows-min gap-4 md:grid-cols-2">
<article class="flex items-center gap-4 rounded-lg border border-gray-100 bg-white p-6 dark:border-gray-800 dark:bg-white/[0.03]">
<span class="rounded-full bg-[#F04743]/20 p-3 text-[#F04743] dark:bg-[#F04743]/20 dark:text-[#F04743]">
<flux:icon.clock />
</span>
<div>
<p class="text-2xl font-medium text-gray-900 dark:text-white">{{ $open }}</p>
<p class="text-sm text-gray-500 dark:text-gray-400">Opened Tickets</p>
</div>
</article>
<article class="flex items-center gap-4 rounded-lg border border-gray-100 bg-white p-6 dark:border-gray-800 dark:bg-white/[0.03]">
<span class="rounded-full bg-[#F04743]/20 p-3 text-[#F04743] dark:bg-[#F04743]/20 dark:text-[#F04743]">
<flux:icon.circle-x />
</span>
<div>
<p class="text-2xl font-medium text-gray-900 dark:text-white">{{ $closed }}</p>
<p class="text-sm text-gray-500 dark:text-gray-400">Closed Tickets</p>
</div>
</article>
</div>
<div x-data="{ show: false, id: 0 }">
<div class="flex-1 overflow-hidden rounded-xl border border-neutral-200 dark:border-neutral-700 dark:bg-white/[0.03]">
<div x-show="!show" class="list">
<div class="flex justify-between items-center p-2 dark:bg-zinc-900 bg-gray-300">
<h3 class="text-md font-semibold text-gray-900 dark:text-white pl-1">Tickets</h3>
<flux:modal.trigger name="create-ticket">
<flux:button class="cursor-pointer">Create Ticket</flux:button>
</flux:modal.trigger>
</div>
</div>
<div x-show="show">
<div class="flex justify-between items-center p-2 dark:bg-zinc-900 bg-gray-300">
<nav class="flex items-center cursor-pointer py-3" x-on:click="show = false">
<flux:icon.chevron-left variant="mini"/>
<flux:text>{{ __('Get back to Tickets') }}</flux:text>
</nav>
</div>
</div>
@if(count($tickets) > 0)
<div class="ticketbox">
<div x-show="!show" class="list">
<!-- Tickets Table -->
<div class="overflow-x-auto shadow-md sm:rounded-lg">
<table class="min-w-full table-auto text-sm text-left text-gray-500 dark:text-gray-400">
<thead class="text-xs text-gray-700 uppercase bg-gray-200 dark:bg-zinc-800 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">ID</th>
<th scope="col" class="px-6 py-3">Subject</th>
<th scope="col" class="px-6 py-3">Status</th>
<th scope="col" class="px-6 py-3">Created Date</th>
<th scope="col" class="px-6 py-3"></th>
</tr>
</thead>
<tbody>
@foreach(collect($tickets)->reverse() as $index => $ticket)
<tr class="border-b dark:border-gray-700 border-gray-200">
<td class="px-6 py-4">#{{ $ticket->ticket_id }}</td>
<td class="px-6 py-4 truncate">{{ $ticket->subject }}</td>
<td class="px-6 py-4">
@if($ticket->status == "open")
<flux:badge size="sm" color="green">Open</flux:badge>
@elseif($ticket->status == "pending")
<flux:badge size="sm" color="yellow">In-Progress</flux:badge>
@else
<flux:badge size="sm" color="red">Closed</flux:badge>
@endif
</td>
<td class="px-6 py-4">{{ $ticket->created_at->diffForHumans() }}</td>
<td class="px-6 py-4">
<button class="cursor-pointer px-3 py-1 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:outline-none"
x-on:click="show = true; id = {{ $index }};" data-id="{{ $index }}"
>
Show
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<div x-show="show" class="message">
@foreach(collect($tickets)->reverse() as $index => $ticket)
<div x-show="id === {{ $index }}" id="ticket-{{ $index }}">
<div class="overflow-x-auto shadow-md sm:rounded-lg p-4">
<div class="flex flex-col lg:flex-row gap-6">
<!-- Left Column (Messages & Reply Form) -->
<div class="w-full lg:w-2/3 space-y-4">
<!-- Customer Message -->
<div class="bg-white dark:bg-zinc-800 border-l-4 shadow rounded p-4">
<div class="flex justify-between items-center mb-1">
<span class="font-semibold text-gray-800 dark:text-gray-200">{{ auth()->user()->name }}</span>
<span class="text-sm text-gray-500">{{ $ticket->created_at->format('F d, Y • h:i A') }}</span>
</div>
<p class="text-gray-700 dark:text-gray-300">Subject: {{ $ticket->subject }}<br/>Message: {{ $ticket->message }}</p>
</div>
@if(count($ticket->responses) > 0)
@foreach($ticket->responses as $response)
<div class="bg-white dark:bg-zinc-800 border-l-4 shadow rounded p-4">
<div class="flex justify-between items-center mb-1">
<span class="font-semibold text-gray-800 dark:text-gray-200">{{ auth()->user()->id === $response->user_id ? auth()->user()->name : 'Support Team' }}</span>
<span class="text-sm text-gray-500">{{ $response->created_at->format('F d, Y • h:i A') }}</span>
</div>
<p class="text-gray-700 dark:text-gray-300">{{ $response->response }}</p>
</div>
@endforeach
@endif
<!-- Reply Form -->
<div class="bg-white dark:bg-zinc-800 p-4 shadow rounded">
<textarea wire:model="response" class="w-full p-3 rounded border border-gray-300 dark:border-zinc-600 bg-white dark:bg-zinc-900 text-gray-800 dark:text-white focus:outline-none focus:ring focus:ring-blue-500" rows="4" placeholder="Type your response..."></textarea>
@error('response')
<div class="my-2 app-primary">
{{ $message }}
</div>
@enderror
<!-- Success/Error Message -->
@if (session()->has('success'))
<div class="my-2" style="color: #00AB55">
{{ session('success') }}
</div>
@endif
@if (session()->has('error'))
<div class="my-2 app-primary">
{{ session('error') }}
</div>
@endif
<flux:button variant="outline" wire:click="reply('{{ $ticket->id }}')">Send Reply</flux:button>
</div>
</div>
<!-- Right Column (Ticket Details) -->
<div class="w-full lg:w-1/3">
<div class="bg-white dark:bg-zinc-800 shadow rounded-lg p-4 space-y-2">
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-200 mb-2">Ticket Details</h2>
<div class="text-gray-700 dark:text-gray-300">
<p><strong>Ticket ID:</strong> #{{ $ticket->ticket_id }}</p>
<p><strong>Created At:</strong> {{ $ticket->created_at->format('F d, Y • h:i A') }}</p>
<p><strong>Last Response:</strong> {{ $ticket->last_response_at ? $ticket->last_response_at->format('F d, Y • h:i A') : 'No responses yet' }}</p>
<span class="flex flex-row gap-2"><p><strong>Status:</strong></p>
@if($ticket->status == "open")
<flux:badge size="sm" color="green">Open</flux:badge>
@elseif($ticket->status == "pending")
<flux:badge size="sm" color="yellow">In-Progress</flux:badge>
@else
<flux:badge size="sm" color="red">Closed</flux:badge>
@endif
</span>
<flux:button class="mt-2 cursor-pointer inbox-btn" wire:click="close('{{ $ticket->id }}')">Close Ticket</flux:button>
</div>
</div>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
@else
<div class="flex justify-center items-center" style="min-height: 400px;">
<p class="text-gray-500 dark:text-gray-400">No Tickets</p>
</div>
@endif
</div>
</div>
</div>
<flux:modal name="create-ticket" class="md:w-96">
<div class="space-y-6">
<div>
<flux:heading size="lg">Create ticket</flux:heading>
@if (session()->has('success'))
<flux:text class="mt-2" style="color: #00AB55">{{ session('success') }}</flux:text>
@endif
@if (session()->has('error'))
<flux:text class="mt-2 app-primary" >{{ session('error') }}</flux:text>
@endif
</div>
<flux:input label="Subject" placeholder="Enter subject" wire:model="subject"/>
<flux:textarea
label="Message"
placeholder="Enter the issue you are facing or just give us feedback what we can improve"
wire:model="message"
/>
<div class="flex">
<flux:spacer />
<flux:button class="cursor-pointer" type="submit" variant="primary" wire:click="store">Create</flux:button>
</div>
</div>
</flux:modal>
</span>

View File

@@ -1,6 +1,7 @@
<?php
use App\Models\Email;
use App\Models\Ticket;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
@@ -34,5 +35,8 @@ Schedule::call(function () {
Artisan::command('cleanMail', function (){
$this->comment(Email::cleanMailbox());
});
Artisan::command('closeTicket', function (){
$this->comment(Ticket::autoClose());
});

View File

@@ -8,6 +8,7 @@ use App\Livewire\Dashboard\Bulk;
use App\Livewire\Dashboard\BulkGmail;
use App\Livewire\Dashboard\Dashboard;
use App\Livewire\Dashboard\Mailbox\Inbox;
use App\Livewire\Dashboard\Support;
use App\Livewire\Frontend\Mailbox;
use App\Livewire\Home;
use App\Livewire\ListBlog;
@@ -60,6 +61,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
Route::get('dashboard/bulk-email-generator', Bulk::class)->name('dashboard.bulk');
Route::get('dashboard/bulk-gmail-generator', BulkGmail::class)->name('dashboard.bulkGmail');
Route::get('dashboard/compose-email', Dashboard::class)->name('dashboard.compose');
Route::get('dashboard/support', Support::class)->name('dashboard.support');
// Checkout Routes
Route::get('checkout/{plan}', function ($pricing_id) {
@@ -74,6 +76,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
->newSubscription('default', $pricing_id)
->allowPromotionCodes()
->checkout([
'billing_address_collection' => 'required',
'success_url' => route('checkout.success'),
'cancel_url' => route('checkout.cancel'),
]);

View File

@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 16, 2025 at 10:52 PM
-- Generation Time: May 16, 2025 at 10:53 PM
-- Server version: 10.4.28-MariaDB
-- PHP Version: 8.3.21
@@ -1169,7 +1169,9 @@ INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
(36, '2025_05_03_200503_add_user_id_to_logs_table', 18),
(39, '2025_05_05_212255_create_premium_emails_table', 19),
(43, '2025_05_16_015550_create_activation_keys_table', 20),
(44, '2025_05_16_024757_add_shoppy_and_accept_columns_to_plans_table', 21);
(44, '2025_05_16_024757_add_shoppy_and_accept_columns_to_plans_table', 21),
(53, '2025_05_16_072530_create_tickets_table', 22),
(54, '2025_05_16_072547_create_ticket_responses_table', 22);
-- --------------------------------------------------------
@@ -1461,6 +1463,41 @@ INSERT INTO `subscription_items` (`id`, `subscription_id`, `stripe_id`, `stripe_
-- --------------------------------------------------------
--
-- Table structure for table `tickets`
--
CREATE TABLE `tickets` (
`id` bigint(20) UNSIGNED NOT NULL,
`user_id` bigint(20) UNSIGNED NOT NULL,
`ticket_id` varchar(6) NOT NULL,
`subject` varchar(255) NOT NULL,
`message` text NOT NULL,
`status` enum('open','closed','pending') NOT NULL DEFAULT 'open',
`ip_address` varchar(45) DEFAULT NULL,
`last_response_at` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `ticket_responses`
--
CREATE TABLE `ticket_responses` (
`id` bigint(20) UNSIGNED NOT NULL,
`ticket_id` bigint(20) UNSIGNED NOT NULL,
`user_id` bigint(20) UNSIGNED NOT NULL,
`response` text NOT NULL,
`ip_address` varchar(45) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `usage_logs`
--
@@ -1679,6 +1716,22 @@ ALTER TABLE `subscription_items`
ADD UNIQUE KEY `subscription_items_stripe_id_unique` (`stripe_id`),
ADD KEY `subscription_items_subscription_id_stripe_price_index` (`subscription_id`,`stripe_price`);
--
-- Indexes for table `tickets`
--
ALTER TABLE `tickets`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `tickets_ticket_id_unique` (`ticket_id`),
ADD KEY `tickets_user_id_foreign` (`user_id`);
--
-- Indexes for table `ticket_responses`
--
ALTER TABLE `ticket_responses`
ADD PRIMARY KEY (`id`),
ADD KEY `ticket_responses_ticket_id_foreign` (`ticket_id`),
ADD KEY `ticket_responses_user_id_foreign` (`user_id`);
--
-- Indexes for table `usage_logs`
--
@@ -1762,7 +1815,7 @@ ALTER TABLE `metas`
-- AUTO_INCREMENT for table `migrations`
--
ALTER TABLE `migrations`
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=53;
MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=55;
--
-- AUTO_INCREMENT for table `pages`
@@ -1800,6 +1853,18 @@ ALTER TABLE `subscriptions`
ALTER TABLE `subscription_items`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28;
--
-- AUTO_INCREMENT for table `tickets`
--
ALTER TABLE `tickets`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `ticket_responses`
--
ALTER TABLE `ticket_responses`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `usage_logs`
--
@@ -1840,6 +1905,19 @@ ALTER TABLE `logs`
ALTER TABLE `premium_emails`
ADD CONSTRAINT `premium_emails_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
--
-- Constraints for table `tickets`
--
ALTER TABLE `tickets`
ADD CONSTRAINT `tickets_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
--
-- Constraints for table `ticket_responses`
--
ALTER TABLE `ticket_responses`
ADD CONSTRAINT `ticket_responses_ticket_id_foreign` FOREIGN KEY (`ticket_id`) REFERENCES `tickets` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `ticket_responses_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
--
-- Constraints for table `usage_logs`
--