Skip to content
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
18 changes: 18 additions & 0 deletions resources/views/head.antlers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script src='https://chat-assets.frontapp.com/v1/chat.bundle.js'></script>
<script>
window.addEventListener('load', (event) => {
fetch('/front/config')
.then(response => response.json())
.then(options => {
window.FrontChat(
'init', {
chatId: options.chatId,
email: options.email,
name: options.name,
userHash: options.hash,
useDefaultLauncher: true
}
);
})
});
</script>
16 changes: 0 additions & 16 deletions resources/views/head.blade.php

This file was deleted.

6 changes: 6 additions & 0 deletions routes/actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

use Illuminate\Support\Facades\Route;
use TransformStudios\Front\Http\Controllers\ConfigController;

Route::get('config', ConfigController::class)->name('front.config');
38 changes: 38 additions & 0 deletions src/Http/Controllers/ConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace TransformStudios\Front\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Statamic\Facades\User;

class ConfigController extends Controller
{
public function __invoke(): JsonResponse
{
$email = null;
$hash = null;
$name = null;

if ($user = User::current()) {
$email = $user->email();
$hash = hash_hmac('sha256', $email, config('front.secret_key'));
$name = $user->get('name');
}

return response()->json([
'configured' => $this->isConfigured(),
'chatId' => config('front.chat.id'),
'email' => $email,
'name' => $name,
'hash' => $hash,
]);
}

private function isConfigured(): bool
{
return config('front.chat.show_on_front_end') &&
config('front.chat.id') &&
config('front.secret_key');
}
}
33 changes: 0 additions & 33 deletions src/Http/Livewire/Scripts.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\View;
use Livewire\Livewire;
use Statamic\Facades\User as UserFacade;
use Statamic\Providers\AddonServiceProvider;
use Statamic\Statamic;
use Statamic\Support\Arr;
use TransformStudios\Front\Http\Livewire\Scripts;
use TransformStudios\Front\Notifications\Channel;

class ServiceProvider extends AddonServiceProvider
{
protected $routes = [
'actions' => __DIR__.'/../routes/actions.php',
];

protected $vite = [
'input' => [
'resources/css/cp.css',
Expand All @@ -28,8 +30,6 @@ public function bootAddon()
{
$this->bootScript();

Livewire::component('front.scripts', Scripts::class);

// needed for testing but not production
// $this->loadViewsFrom(
// __DIR__.'/../resources/views',
Expand Down