Skip to content

Commit

Permalink
Merge pull request #193 from canyongbs/aidapp-121
Browse files Browse the repository at this point in the history
[AIDAPP-121]: Enhance copy/paste capabilities for Knowledge Base Articles and throughout the product.
  • Loading branch information
Orrison authored Jul 31, 2024
2 parents c0e6d26 + 9faa571 commit 6d15d72
Show file tree
Hide file tree
Showing 37 changed files with 425 additions and 1,195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
namespace AidingApp\Division\Filament\Resources\DivisionResource\Pages;

use Filament\Forms\Form;
use FilamentTiptapEditor\TiptapEditor;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\CreateRecord;
use App\Filament\Forms\Components\TiptapEditor;
use AidingApp\Division\Filament\Resources\DivisionResource;

class CreateDivision extends CreateRecord
Expand All @@ -63,12 +63,10 @@ public function form(Form $form): Form
->string(),
TiptapEditor::make('header')
->disk('s3-public')
->visibility('public')
->string()
->columnSpanFull(),
TiptapEditor::make('footer')
->disk('s3-public')
->visibility('public')
->string()
->columnSpanFull(),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
use Filament\Actions\DeleteAction;
use App\Models\NotificationSetting;
use Filament\Forms\Components\Select;
use FilamentTiptapEditor\TiptapEditor;
use AidingApp\Division\Models\Division;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\EditRecord;
use App\Filament\Forms\Components\TiptapEditor;
use AidingApp\Division\Filament\Resources\DivisionResource;

class EditDivision extends EditRecord
Expand All @@ -68,12 +68,10 @@ public function form(Form $form): Form
->columnSpanFull(),
TiptapEditor::make('header')
->disk('s3-public')
->visibility('public')
->string()
->columnSpanFull(),
TiptapEditor::make('footer')
->disk('s3-public')
->visibility('public')
->string()
->columnSpanFull(),
Select::make('notification_setting_id')
Expand Down
12 changes: 10 additions & 2 deletions app-modules/engagement/src/Actions/CreateEngagementBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,22 @@ public function handle(): void
'user_id' => $this->data->user->id,
]);

$this->data->records->each(function (Contact $record) use ($engagementBatch) {
[$body] = tiptap_converter()->saveImages(
$this->data->body,
disk: 's3-public',
record: $engagementBatch,
recordAttribute: 'body',
newImages: $this->data->temporaryBodyImages,
);

$this->data->records->each(function (Contact $record) use ($body, $engagementBatch) {
/** @var Engagement $engagement */
$engagement = $engagementBatch->engagements()->create([
'user_id' => $engagementBatch->user_id,
'recipient_id' => $record->getKey(),
'recipient_type' => $record->getMorphClass(),
'body' => $body,
'subject' => $this->data->subject,
'body' => $this->data->body,
'scheduled' => false,
]);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,20 @@
</COPYRIGHT>
*/

namespace AidingApp\KnowledgeBase\Observers;
namespace AidingApp\Engagement\Actions;

use AidingApp\KnowledgeBase\Models\KnowledgeBaseItem;
use AidingApp\KnowledgeBase\Jobs\KnowledgeBaseItemDownloadExternalMedia;
use App\Support\MediaEncoding\Concerns\ImplementsEncodedMediaProcessing;
use Illuminate\Support\HtmlString;
use Illuminate\Database\Eloquent\Model;

class KnowledgeBaseItemObserver
class GenerateEngagementBodyContent
{
use ImplementsEncodedMediaProcessing;

public function saved(KnowledgeBaseItem $knowledgeBaseItem): void
public function __invoke(string|array $content, array $mergeData, Model $record, string $recordAttribute): HtmlString
{
if (is_string($knowledgeBaseItem->article_details)) {
$knowledgeBaseItem->article_details = json_decode($knowledgeBaseItem->article_details, true);
}

$this->convertPathShortcodesToIdShortcodes($knowledgeBaseItem, ['article_details', 'notes']);

$this->cleanupMediaItems($knowledgeBaseItem, ['article_details', 'notes']);
$content = tiptap_converter()
->mergeTagsMap($mergeData)
->record($record, $recordAttribute)
->asHTML($content);

KnowledgeBaseItemDownloadExternalMedia::dispatch($knowledgeBaseItem);
return str($content)->sanitizeHtml()->toHtmlString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ public function __construct(
public string $deliveryMethod,
public ?string $subject = null,
public ?array $body = null,
public array $temporaryBodyImages = [],
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Forms\Form;
use Illuminate\Support\Collection;
use Filament\Forms\Components\Select;
use FilamentTiptapEditor\TiptapEditor;
Expand All @@ -47,11 +48,11 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Expression;
use Filament\Forms\Components\Wizard\Step;
use FilamentTiptapEditor\Enums\TiptapOutput;
use Filament\Forms\Components\Actions\Action;
use AidingApp\Engagement\Models\EmailTemplate;
use AidingApp\Engagement\Actions\CreateEngagementBatch;
use AidingApp\Engagement\Enums\EngagementDeliveryMethod;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use AidingApp\Engagement\DataTransferObjects\EngagementBatchCreationData;
use AidingApp\Engagement\Filament\Actions\Contracts\HasBulkEngagementAction;
use AidingApp\Engagement\Filament\Resources\EngagementResource\Fields\EngagementSmsBodyField;
Expand Down Expand Up @@ -86,16 +87,13 @@ public static function make(string $context)
->columnSpanFull(),
TiptapEditor::make('body')
->disk('s3-public')
->visibility('public')
->directory('editor-images/engagements')
->label('Body')
->mergeTags([
'contact full name',
'contact email',
])
->showMergeTagsInBlocksPanel(false)
->profile('email')
->output(TiptapOutput::Json)
->required()
->hintAction(fn (TiptapEditor $component) => Action::make('loadEmailTemplate')
->form([
Expand Down Expand Up @@ -144,21 +142,30 @@ public static function make(string $context)
return;
}

$component->state($template->content);
$component->state(
$component->generateImageUrls($template->content),
);
}))
->hidden(fn (Get $get): bool => $get('delivery_method') === EngagementDeliveryMethod::Sms->value)
->helperText('You can insert contact information by typing {{ and choosing a merge value to insert.')
->columnSpanFull(),
EngagementSmsBodyField::make(context: 'create'),
]),
])
->action(function (Collection $records, array $data) {
->action(function (Collection $records, array $data, Form $form) {
CreateEngagementBatch::dispatch(EngagementBatchCreationData::from([
'user' => auth()->user(),
'records' => $records,
'deliveryMethod' => $data['delivery_method'],
'subject' => $data['subject'] ?? null,
'body' => $data['body'] ?? null,
'temporaryBodyImages' => array_map(
fn (TemporaryUploadedFile $file): array => [
'extension' => $file->getClientOriginalExtension(),
'path' => (fn () => $this->path)->call($file),
],
$form->getFlatFields()['body']->getTemporaryImages(),
),
]));
})
->modalSubmitActionLabel('Send')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,31 @@

namespace AidingApp\Engagement\Filament\Actions;

use Closure;
use Illuminate\Database\Eloquent\Model;
use AidingApp\Engagement\Models\Engagement;
use AidingApp\Engagement\Actions\CreateEngagementDeliverable;

class CreateOnDemandEngagement
{
public function __invoke(Model $educatable, array $data): void
public function __invoke(Model $educatable, array $data, ?Closure $afterCreation = null): Engagement
{
$engagement = $educatable->engagements()->create([
'subject' => $data['subject'] ?? null,
'body' => $data['body'] ?? null,
'scheduled' => false,
]);

if ($afterCreation) {
$afterCreation($engagement);
}

$createEngagementDeliverable = resolve(CreateEngagementDeliverable::class);

$createEngagementDeliverable($engagement, $data['delivery_method']);

$engagement->deliverable->driver()->deliver();

return $engagement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@

namespace AidingApp\Engagement\Filament\Actions;

use Filament\Forms\Form;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Illuminate\Database\Eloquent\Model;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Wizard\Step;
use AidingApp\Engagement\Models\Engagement;
use AidingApp\Engagement\Enums\EngagementDeliveryMethod;

class EngagementCreateAction
Expand Down Expand Up @@ -94,10 +96,14 @@ public static function make(Model $educatable)
}),
]),
])
->action(function (array $data) use ($educatable) {
->action(function (array $data, Form $form) use ($educatable) {
$createOnDemandEngagement = resolve(CreateOnDemandEngagement::class);

$createOnDemandEngagement($educatable, $data);
$createOnDemandEngagement(
$educatable,
$data,
afterCreation: fn (Engagement $engagement) => $form->model($engagement)->saveRelationships(),
);
})
->modalSubmitActionLabel('Send')
->modalCloseButton(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\CreateRecord;
use FilamentTiptapEditor\Enums\TiptapOutput;
use AidingApp\Engagement\Filament\Resources\EmailTemplateResource;

class CreateEmailTemplate extends CreateRecord
Expand All @@ -62,14 +61,11 @@ public function form(Form $form): Form
->string(),
TiptapEditor::make('content')
->disk('s3-public')
->visibility('public')
->directory('editor-images/email-templates')
->mergeTags([
'contact full name',
'contact email',
])
->profile('email')
->output(TiptapOutput::Json)
->columnSpanFull()
->extraInputAttributes(['style' => 'min-height: 12rem;'])
->required(),
Expand Down
Loading

0 comments on commit 6d15d72

Please sign in to comment.