feat: refactory post controlller.
This commit is contained in:
parent
e6ac6c1392
commit
af45d4586f
32 changed files with 142 additions and 326 deletions
|
|
@ -45,7 +45,7 @@ public function accept(Request $request, WorkspaceInvite $invite): RedirectRespo
|
|||
|
||||
// Verify the invite is for this user
|
||||
if ($invite->email !== $user->email) {
|
||||
session()->flash('flash.banner', 'This invite is for a different email address.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.wrong_email'));
|
||||
session()->flash('flash.bannerStyle', 'danger');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
@ -55,7 +55,7 @@ public function accept(Request $request, WorkspaceInvite $invite): RedirectRespo
|
|||
if ($invite->workspace->hasMember($user)) {
|
||||
$invite->delete();
|
||||
|
||||
session()->flash('flash.banner', 'You are already a member of this workspace.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.already_member'));
|
||||
session()->flash('flash.bannerStyle', 'info');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
@ -66,7 +66,7 @@ public function accept(Request $request, WorkspaceInvite $invite): RedirectRespo
|
|||
$invite->accept($user);
|
||||
$user->update(['current_workspace_id' => $workspaceId]);
|
||||
|
||||
session()->flash('flash.banner', 'Welcome! You are now a member of the workspace.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.invite_accepted'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
@ -81,7 +81,7 @@ public function decline(Request $request, WorkspaceInvite $invite): RedirectResp
|
|||
|
||||
// Verify the invite is for this user
|
||||
if ($invite->email !== $user->email) {
|
||||
session()->flash('flash.banner', 'This invite is for a different email address.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.wrong_email'));
|
||||
session()->flash('flash.bannerStyle', 'danger');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
@ -89,7 +89,7 @@ public function decline(Request $request, WorkspaceInvite $invite): RedirectResp
|
|||
|
||||
$invite->delete();
|
||||
|
||||
session()->flash('flash.banner', 'Invite declined.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.invite_declined'));
|
||||
session()->flash('flash.bannerStyle', 'info');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public function disconnect(Request $request, SocialAccount $account): RedirectRe
|
|||
|
||||
$account->delete();
|
||||
|
||||
session()->flash('flash.banner', 'Account disconnected successfully!');
|
||||
session()->flash('flash.banner', __('accounts.flash.disconnected'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public function storeStep2(Request $request): SymfonyResponse|RedirectResponse
|
|||
'setup' => Setup::Completed,
|
||||
]);
|
||||
|
||||
session()->flash('flash.banner', 'Welcome to TryPost!');
|
||||
session()->flash('flash.banner', __('auth.flash.welcome'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
@ -121,7 +121,7 @@ public function complete(Request $request): RedirectResponse
|
|||
'setup' => Setup::Completed,
|
||||
]);
|
||||
|
||||
session()->flash('flash.banner', 'Welcome to TryPost! Your trial has started.');
|
||||
session()->flash('flash.banner', __('auth.flash.welcome_trial'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('calendar');
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
use App\Enums\Post\Status as PostStatus;
|
||||
use App\Enums\PostPlatform\ContentType;
|
||||
use App\Enums\SocialAccount\Platform;
|
||||
use App\Http\Requests\StorePostRequest;
|
||||
use App\Http\Requests\UpdatePostRequest;
|
||||
use App\Jobs\PublishPost;
|
||||
use App\Models\Post;
|
||||
|
|
@ -98,7 +97,7 @@ public function calendar(Request $request): Response|RedirectResponse
|
|||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request): RedirectResponse
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$workspace = $request->user()->currentWorkspace;
|
||||
|
||||
|
|
@ -111,7 +110,7 @@ public function create(Request $request): RedirectResponse
|
|||
$socialAccounts = $workspace->socialAccounts;
|
||||
|
||||
if ($socialAccounts->isEmpty()) {
|
||||
session()->flash('flash.banner', 'Connect at least one social network before creating a post.');
|
||||
session()->flash('flash.banner', __('posts.flash.connect_first'));
|
||||
session()->flash('flash.bannerStyle', 'danger');
|
||||
|
||||
return redirect()->route('accounts');
|
||||
|
|
@ -145,50 +144,6 @@ public function create(Request $request): RedirectResponse
|
|||
return redirect()->route('posts.edit', $post);
|
||||
}
|
||||
|
||||
public function store(StorePostRequest $request): RedirectResponse
|
||||
{
|
||||
$workspace = $request->user()->currentWorkspace;
|
||||
|
||||
if (! $workspace) {
|
||||
return redirect()->route('workspaces.create');
|
||||
}
|
||||
|
||||
$this->authorize('view', $workspace);
|
||||
|
||||
$post = $workspace->posts()->create([
|
||||
'user_id' => $request->user()->id,
|
||||
'status' => $request->input('status', PostStatus::Draft),
|
||||
'synced' => $request->input('synced', true),
|
||||
'scheduled_at' => $request->input('scheduled_at'),
|
||||
]);
|
||||
|
||||
foreach ($request->input('platforms', []) as $platformData) {
|
||||
$postPlatform = $post->postPlatforms()->create([
|
||||
'social_account_id' => $platformData['social_account_id'],
|
||||
'platform' => $platformData['platform'],
|
||||
'content' => $platformData['content'],
|
||||
'content_type' => $platformData['content_type'] ?? null,
|
||||
'status' => 'pending',
|
||||
'enabled' => $platformData['enabled'] ?? true,
|
||||
]);
|
||||
|
||||
if (! empty($platformData['media_ids'])) {
|
||||
$postPlatform->media()->whereIn('id', $platformData['media_ids'])->update([
|
||||
'post_platform_id' => $postPlatform->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$route = $request->input('status') === PostStatus::Scheduled->value
|
||||
? 'calendar'
|
||||
: 'posts.index';
|
||||
|
||||
session()->flash('flash.banner', 'Post created successfully!');
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route($route);
|
||||
}
|
||||
|
||||
public function edit(Request $request, Post $post): Response|RedirectResponse
|
||||
{
|
||||
$workspace = $request->user()->currentWorkspace;
|
||||
|
|
@ -254,7 +209,7 @@ public function update(UpdatePostRequest $request, Post $post): RedirectResponse
|
|||
}
|
||||
|
||||
if ($post->status === PostStatus::Published) {
|
||||
session()->flash('flash.banner', 'Published posts cannot be edited.');
|
||||
session()->flash('flash.banner', __('posts.flash.cannot_edit_published'));
|
||||
session()->flash('flash.bannerStyle', 'danger');
|
||||
|
||||
return back();
|
||||
|
|
@ -300,7 +255,7 @@ public function update(UpdatePostRequest $request, Post $post): RedirectResponse
|
|||
if ($status === 'publishing') {
|
||||
PublishPost::dispatch($post);
|
||||
|
||||
session()->flash('flash.banner', 'Post is being published!');
|
||||
session()->flash('flash.banner', __('posts.flash.publishing'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('posts.edit', $post);
|
||||
|
|
@ -308,16 +263,12 @@ public function update(UpdatePostRequest $request, Post $post): RedirectResponse
|
|||
|
||||
// Redirect to show page for schedule action
|
||||
if ($status === 'scheduled') {
|
||||
session()->flash('flash.banner', 'Post scheduled successfully!');
|
||||
session()->flash('flash.banner', __('posts.flash.scheduled'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('posts.edit', $post);
|
||||
}
|
||||
|
||||
// Stay on edit page for save action
|
||||
session()->flash('flash.banner', 'Post saved!');
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
|
|
@ -337,7 +288,7 @@ public function destroy(Request $request, Post $post): RedirectResponse
|
|||
|
||||
$post->delete();
|
||||
|
||||
session()->flash('flash.banner', 'Post deleted successfully!');
|
||||
session()->flash('flash.banner', __('posts.flash.deleted'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public function update(PasswordUpdateRequest $request): RedirectResponse
|
|||
'password' => $request->password,
|
||||
]);
|
||||
|
||||
session()->flash('flash.banner', 'Password updated successfully!');
|
||||
session()->flash('flash.banner', __('settings.flash.password_updated'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public function update(ProfileUpdateRequest $request): RedirectResponse
|
|||
|
||||
$request->user()->save();
|
||||
|
||||
session()->flash('flash.banner', 'Profile updated successfully!');
|
||||
session()->flash('flash.banner', __('settings.flash.profile_updated'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return to_route('profile.edit');
|
||||
|
|
@ -62,7 +62,7 @@ public function updateLanguage(Request $request): RedirectResponse
|
|||
// Refresh the user model to clear cached language relationship
|
||||
$request->user()->refresh();
|
||||
|
||||
session()->flash('flash.banner', 'Language updated successfully!');
|
||||
session()->flash('flash.banner', __('settings.flash.language_updated'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public function updateSettings(UpdateWorkspaceRequest $request): RedirectRespons
|
|||
|
||||
$workspace->update($request->validated());
|
||||
|
||||
session()->flash('flash.banner', 'Settings updated successfully!');
|
||||
session()->flash('flash.banner', __('settings.flash.workspace_updated'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('workspace.settings');
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public function store(Request $request): RedirectResponse
|
|||
|
||||
$workspace->hashtags()->create($validated);
|
||||
|
||||
session()->flash('flash.banner', 'Hashtag group created successfully!');
|
||||
session()->flash('flash.banner', __('hashtags.flash.created'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('hashtags.index');
|
||||
|
|
@ -70,7 +70,7 @@ public function update(Request $request, WorkspaceHashtag $hashtag): RedirectRes
|
|||
|
||||
$hashtag->update($validated);
|
||||
|
||||
session()->flash('flash.banner', 'Hashtag group updated successfully!');
|
||||
session()->flash('flash.banner', __('hashtags.flash.updated'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('hashtags.index');
|
||||
|
|
@ -92,7 +92,7 @@ public function destroy(Request $request, WorkspaceHashtag $hashtag): RedirectRe
|
|||
|
||||
$hashtag->delete();
|
||||
|
||||
session()->flash('flash.banner', 'Hashtag group deleted successfully!');
|
||||
session()->flash('flash.banner', __('hashtags.flash.deleted'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('hashtags.index');
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public function store(StoreWorkspaceInviteRequest $request): RedirectResponse
|
|||
|
||||
Mail::to($invite->email)->send(new WorkspaceInviteMail($invite));
|
||||
|
||||
session()->flash('flash.banner', 'Invite sent successfully!');
|
||||
session()->flash('flash.banner', __('settings.members.flash.invite_sent'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
@ -110,7 +110,7 @@ public function destroy(Request $request, WorkspaceInvite $invite): RedirectResp
|
|||
|
||||
$invite->delete();
|
||||
|
||||
session()->flash('flash.banner', 'Invite deleted.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.invite_deleted'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
@ -132,7 +132,7 @@ public function removeMember(Request $request, string $userId): RedirectResponse
|
|||
|
||||
$workspace->members()->detach($userId);
|
||||
|
||||
session()->flash('flash.banner', 'Member removed successfully.');
|
||||
session()->flash('flash.banner', __('settings.members.flash.member_removed'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return back();
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public function store(Request $request): RedirectResponse
|
|||
|
||||
$workspace->labels()->create($validated);
|
||||
|
||||
session()->flash('flash.banner', 'Label created successfully!');
|
||||
session()->flash('flash.banner', __('labels.flash.created'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('labels.index');
|
||||
|
|
@ -70,7 +70,7 @@ public function update(Request $request, WorkspaceLabel $label): RedirectRespons
|
|||
|
||||
$label->update($validated);
|
||||
|
||||
session()->flash('flash.banner', 'Label updated successfully!');
|
||||
session()->flash('flash.banner', __('labels.flash.updated'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('labels.index');
|
||||
|
|
@ -92,7 +92,7 @@ public function destroy(Request $request, WorkspaceLabel $label): RedirectRespon
|
|||
|
||||
$label->delete();
|
||||
|
||||
session()->flash('flash.banner', 'Label deleted successfully!');
|
||||
session()->flash('flash.banner', __('labels.flash.deleted'));
|
||||
session()->flash('flash.bannerStyle', 'success');
|
||||
|
||||
return redirect()->route('labels.index');
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\Post\Status as PostStatus;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StorePostRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'status' => ['required', Rule::enum(PostStatus::class)],
|
||||
'scheduled_at' => ['required_if:status,'.PostStatus::Scheduled->value, 'nullable', 'date', 'after:now'],
|
||||
'platforms' => ['required', 'array', 'min:1'],
|
||||
'platforms.*.social_account_id' => ['required', 'uuid', 'exists:social_accounts,id'],
|
||||
'platforms.*.platform' => ['required', 'string'],
|
||||
'platforms.*.content' => ['nullable', 'string', 'max:5000'],
|
||||
'platforms.*.media_ids' => ['nullable', 'array'],
|
||||
'platforms.*.media_ids.*' => ['uuid', 'exists:post_media,id'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'platforms.required' => 'Selecione pelo menos uma rede social.',
|
||||
'platforms.min' => 'Selecione pelo menos uma rede social.',
|
||||
'scheduled_at.required_if' => 'A data de agendamento é obrigatória para posts agendados.',
|
||||
'scheduled_at.after' => 'A data de agendamento deve ser no futuro.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -56,4 +56,8 @@
|
|||
'no_pages_description' => 'You are not an administrator of any LinkedIn page.',
|
||||
'page_label' => 'LinkedIn Page',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'disconnected' => 'Account disconnected successfully!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -17,4 +17,9 @@
|
|||
'password' => 'The provided password is incorrect.',
|
||||
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
|
||||
|
||||
'flash' => [
|
||||
'welcome' => 'Welcome to TryPost!',
|
||||
'welcome_trial' => 'Welcome to TryPost! Your trial has started.',
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -39,4 +39,10 @@
|
|||
'confirm' => 'Delete',
|
||||
'cancel' => 'Cancel',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'created' => 'Hashtag group created successfully!',
|
||||
'updated' => 'Hashtag group updated successfully!',
|
||||
'deleted' => 'Hashtag group deleted successfully!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -33,4 +33,10 @@
|
|||
'confirm' => 'Delete',
|
||||
'cancel' => 'Cancel',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'created' => 'Label created successfully!',
|
||||
'updated' => 'Label updated successfully!',
|
||||
'deleted' => 'Label deleted successfully!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -204,4 +204,12 @@
|
|||
'bluesky' => 'Bluesky',
|
||||
'mastodon' => 'Mastodon',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'scheduled' => 'Post scheduled successfully!',
|
||||
'publishing' => 'Post is being published!',
|
||||
'deleted' => 'Post deleted successfully!',
|
||||
'cannot_edit_published' => 'Published posts cannot be edited.',
|
||||
'connect_first' => 'Connect at least one social network before creating a post.',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -100,5 +100,22 @@
|
|||
'admin' => 'Admin',
|
||||
'member' => 'Member',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'invite_sent' => 'Invite sent successfully!',
|
||||
'invite_deleted' => 'Invite deleted.',
|
||||
'member_removed' => 'Member removed successfully.',
|
||||
'wrong_email' => 'This invite is for a different email address.',
|
||||
'already_member' => 'You are already a member of this workspace.',
|
||||
'invite_accepted' => 'Welcome! You are now a member of the workspace.',
|
||||
'invite_declined' => 'Invite declined.',
|
||||
],
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'profile_updated' => 'Profile updated successfully!',
|
||||
'language_updated' => 'Language updated successfully!',
|
||||
'password_updated' => 'Password updated successfully!',
|
||||
'workspace_updated' => 'Settings updated successfully!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -56,4 +56,8 @@
|
|||
'no_pages_description' => 'Você não é administrador de nenhuma página do LinkedIn.',
|
||||
'page_label' => 'Página do LinkedIn',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'disconnected' => 'Conta desconectada com sucesso!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -17,4 +17,9 @@
|
|||
'password' => 'A senha fornecida está incorreta.',
|
||||
'throttle' => 'Muitas tentativas de login. Por favor, tente novamente em :seconds segundos.',
|
||||
|
||||
'flash' => [
|
||||
'welcome' => 'Bem-vindo ao TryPost!',
|
||||
'welcome_trial' => 'Bem-vindo ao TryPost! Seu período de teste começou.',
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -39,4 +39,10 @@
|
|||
'confirm' => 'Excluir',
|
||||
'cancel' => 'Cancelar',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'created' => 'Grupo de hashtags criado com sucesso!',
|
||||
'updated' => 'Grupo de hashtags atualizado com sucesso!',
|
||||
'deleted' => 'Grupo de hashtags excluído com sucesso!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -33,4 +33,10 @@
|
|||
'confirm' => 'Excluir',
|
||||
'cancel' => 'Cancelar',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'created' => 'Etiqueta criada com sucesso!',
|
||||
'updated' => 'Etiqueta atualizada com sucesso!',
|
||||
'deleted' => 'Etiqueta excluída com sucesso!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -204,4 +204,12 @@
|
|||
'bluesky' => 'Bluesky',
|
||||
'mastodon' => 'Mastodon',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'scheduled' => 'Post agendado com sucesso!',
|
||||
'publishing' => 'Post está sendo publicado!',
|
||||
'deleted' => 'Post excluído com sucesso!',
|
||||
'cannot_edit_published' => 'Posts publicados não podem ser editados.',
|
||||
'connect_first' => 'Conecte pelo menos uma rede social antes de criar um post.',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -100,5 +100,22 @@
|
|||
'admin' => 'Administrador',
|
||||
'member' => 'Membro',
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'invite_sent' => 'Convite enviado com sucesso!',
|
||||
'invite_deleted' => 'Convite excluído.',
|
||||
'member_removed' => 'Membro removido com sucesso.',
|
||||
'wrong_email' => 'Este convite é para um endereço de e-mail diferente.',
|
||||
'already_member' => 'Você já é membro deste workspace.',
|
||||
'invite_accepted' => 'Bem-vindo! Você agora é membro do workspace.',
|
||||
'invite_declined' => 'Convite recusado.',
|
||||
],
|
||||
],
|
||||
|
||||
'flash' => [
|
||||
'profile_updated' => 'Perfil atualizado com sucesso!',
|
||||
'language_updated' => 'Idioma atualizado com sucesso!',
|
||||
'password_updated' => 'Senha atualizada com sucesso!',
|
||||
'workspace_updated' => 'Configurações atualizadas com sucesso!',
|
||||
],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Link, router, usePage } from '@inertiajs/vue3';
|
|||
import { IconBrandDiscord, IconCalendar, IconCheck, IconSelector, IconFileText, IconHash, IconLogout, IconPlus, IconSettings, IconAffiliate, IconPencil, IconFileCheck, IconTag, IconUser, IconClock, IconMessageCircle, IconBell, IconBook, IconSun, IconMoon, IconDeviceDesktop, IconLanguage } from '@tabler/icons-vue';
|
||||
import { loadLanguageAsync, trans } from 'laravel-vue-i18n';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { create as createPost } from '@/actions/App/Http/Controllers/PostController';
|
||||
import { store as storePost } from '@/actions/App/Http/Controllers/PostController';
|
||||
import { updateLanguage } from '@/actions/App/Http/Controllers/Settings/ProfileController';
|
||||
import { computed } from 'vue';
|
||||
import dayjs from '@/dayjs';
|
||||
|
|
@ -242,7 +242,7 @@ function handleLogout() {
|
|||
<div class="grid flex-1 text-left text-sm leading-tight">
|
||||
<span class="truncate font-semibold">{{ auth.user.name }}</span>
|
||||
<span class="truncate text-xs text-muted-foreground">{{ auth.user.email
|
||||
}}</span>
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</DropdownMenuLabel>
|
||||
|
|
@ -359,7 +359,7 @@ function handleLogout() {
|
|||
<SidebarContent>
|
||||
<!-- Create Post Button -->
|
||||
<div v-if="currentWorkspace" class="px-2 py-2">
|
||||
<Link :href="createPost.url()">
|
||||
<Link :href="storePost.url()" method="post" class="w-full">
|
||||
<Button :size="sidebarState === 'collapsed' ? 'icon' : 'default'" class="w-full">
|
||||
<IconPlus v-if="sidebarState === 'collapsed'" class="size-4" />
|
||||
<span v-if="sidebarState === 'expanded'">{{ $t('sidebar.create_post') }}</span>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|||
import dayjs from '@/dayjs';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { calendar } from '@/routes';
|
||||
import { create as createPost, edit as editPost } from '@/routes/posts';
|
||||
import { store as storePost, edit as editPost } from '@/routes/posts';
|
||||
import { type BreadcrumbItemType } from '@/types';
|
||||
|
||||
interface PostPlatform {
|
||||
|
|
@ -233,7 +233,7 @@ const formatTime = (scheduledAt: string): string => {
|
|||
<TabsTrigger value="month">{{ $t('calendar.month') }}</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<Link :href="createPost.url()">
|
||||
<Link :href="storePost.url()" method="post">
|
||||
<Button>
|
||||
{{ $t('calendar.new_post') }}
|
||||
</Button>
|
||||
|
|
@ -261,7 +261,7 @@ const formatTime = (scheduledAt: string): string => {
|
|||
<!-- Day Content -->
|
||||
<div class="flex-1 overflow-y-auto p-2 space-y-2">
|
||||
<!-- Add Post Button -->
|
||||
<Link :href="createPost.url({ query: { date: day.format('YYYY-MM-DD') } })"
|
||||
<Link :href="storePost.url({ query: { date: day.format('YYYY-MM-DD') } })" method="post"
|
||||
class="flex items-center justify-center p-2 rounded border border-dashed border-muted-foreground/30 text-muted-foreground hover:border-primary hover:text-primary hover:bg-primary/5 transition-colors">
|
||||
<IconPlus class="h-4 w-4" />
|
||||
</Link>
|
||||
|
|
@ -326,7 +326,7 @@ const formatTime = (scheduledAt: string): string => {
|
|||
}">
|
||||
{{ day.format('D') }}
|
||||
</span>
|
||||
<Link :href="createPost.url({ query: { date: day.format('YYYY-MM-DD') } })"
|
||||
<Link :href="storePost.url({ query: { date: day.format('YYYY-MM-DD') } })" method="post"
|
||||
class="opacity-0 group-hover:opacity-100 focus:opacity-100 p-1 rounded text-muted-foreground hover:text-primary hover:bg-primary/10 transition-all">
|
||||
<IconPlus class="h-4 w-4" />
|
||||
</Link>
|
||||
|
|
|
|||
|
|
@ -757,7 +757,7 @@ const deletePost = () => {
|
|||
<div class="flex-1 overflow-hidden">
|
||||
<div v-if="activePlatform && selectedPlatformIds.length > 0" class="h-full flex">
|
||||
<!-- Left Side: Form -->
|
||||
<div class="w-1/2 border-r overflow-y-auto relative">
|
||||
<div class="w-1/2 border-r overflow-y-auto relative ">
|
||||
<!-- Autosave indicator -->
|
||||
<div v-if="!isReadOnly && (isSaving || showSaved)" class="absolute top-4 left-6 z-10">
|
||||
<span v-if="isSaving" class="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import { Skeleton } from '@/components/ui/skeleton';
|
|||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import dayjs from '@/dayjs';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import { index as postsIndex, create as createPost, edit as editPost, destroy as destroyPost } from '@/actions/App/Http/Controllers/PostController';
|
||||
import { index as postsIndex, store as storePost, edit as editPost, destroy as destroyPost } from '@/actions/App/Http/Controllers/PostController';
|
||||
import { type BreadcrumbItemType } from '@/types';
|
||||
|
||||
interface SocialAccount {
|
||||
|
|
@ -165,7 +165,7 @@ const handleDelete = (post: Post) => {
|
|||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Link :href="createPost.url()">
|
||||
<Link :href="storePost.url()" method="post">
|
||||
<Button>
|
||||
{{ $t('posts.new_post') }}
|
||||
</Button>
|
||||
|
|
@ -181,7 +181,7 @@ const handleDelete = (post: Post) => {
|
|||
<p class="mt-2 text-sm text-muted-foreground">
|
||||
{{ currentStatus ? $t('posts.no_posts_status', { status: $t(`posts.status.${currentStatus}`) }) : $t('posts.start_creating') }}
|
||||
</p>
|
||||
<Link v-if="!currentStatus" :href="createPost.url()" class="mt-4">
|
||||
<Link v-if="!currentStatus" :href="storePost.url()" method="post" class="mt-4">
|
||||
<Button>
|
||||
<IconPlus class="h-4 w-4" />
|
||||
{{ $t('posts.create_post') }}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@
|
|||
Route::get('calendar', [PostController::class, 'calendar'])->name('calendar');
|
||||
|
||||
// Posts
|
||||
Route::get('posts/create', [PostController::class, 'create'])->name('posts.create');
|
||||
Route::get('posts/{status?}', [PostController::class, 'index'])->name('posts.index')->where('status', 'draft|scheduled|published');
|
||||
Route::post('posts', [PostController::class, 'store'])->name('posts.store');
|
||||
Route::get('posts/{post}/edit', [PostController::class, 'edit'])->name('posts.edit');
|
||||
|
|
|
|||
|
|
@ -80,23 +80,23 @@
|
|||
);
|
||||
});
|
||||
|
||||
// Create tests
|
||||
test('create post requires authentication', function () {
|
||||
$response = $this->get(route('posts.create'));
|
||||
// Store tests
|
||||
test('store post requires authentication', function () {
|
||||
$response = $this->post(route('posts.store'));
|
||||
|
||||
$response->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
test('create post redirects to accounts if no social accounts connected', function () {
|
||||
test('store post redirects to accounts if no social accounts connected', function () {
|
||||
$this->socialAccount->delete();
|
||||
|
||||
$response = $this->actingAs($this->user)->get(route('posts.create'));
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'));
|
||||
|
||||
$response->assertRedirect(route('accounts'));
|
||||
});
|
||||
|
||||
test('create post creates draft and redirects to edit', function () {
|
||||
$response = $this->actingAs($this->user)->get(route('posts.create'));
|
||||
test('store post creates draft and redirects to edit', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'));
|
||||
|
||||
$response->assertRedirect();
|
||||
|
||||
|
|
@ -247,7 +247,9 @@
|
|||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($this->user)->delete(route('posts.destroy', $post));
|
||||
$response = $this->actingAs($this->user)
|
||||
->from(route('calendar'))
|
||||
->delete(route('posts.destroy', $post));
|
||||
|
||||
$response->assertRedirect(route('calendar'));
|
||||
expect(Post::find($post->id))->toBeNull();
|
||||
|
|
|
|||
|
|
@ -1,189 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\Post\Status as PostStatus;
|
||||
use App\Enums\User\Setup;
|
||||
use App\Models\SocialAccount;
|
||||
use App\Models\User;
|
||||
use App\Models\Workspace;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create(['setup' => Setup::Completed]);
|
||||
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
||||
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
||||
$this->socialAccount = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id]);
|
||||
});
|
||||
|
||||
test('store post request validates status is required', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('status');
|
||||
});
|
||||
|
||||
test('store post request validates status is valid enum', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => 'invalid_status',
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('status');
|
||||
});
|
||||
|
||||
test('store post request validates scheduled_at is required for scheduled posts', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Scheduled->value,
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('scheduled_at');
|
||||
});
|
||||
|
||||
test('store post request validates scheduled_at must be in future', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Scheduled->value,
|
||||
'scheduled_at' => now()->subDay()->toISOString(),
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('scheduled_at');
|
||||
});
|
||||
|
||||
test('store post request validates platforms is required', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms');
|
||||
});
|
||||
|
||||
test('store post request validates platforms is array', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => 'not-an-array',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms');
|
||||
});
|
||||
|
||||
test('store post request validates platforms has at least one item', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => [],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms');
|
||||
});
|
||||
|
||||
test('store post request validates platform social_account_id is required', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => [
|
||||
[
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms.0.social_account_id');
|
||||
});
|
||||
|
||||
test('store post request validates platform social_account_id exists', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => '00000000-0000-0000-0000-000000000000',
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms.0.social_account_id');
|
||||
});
|
||||
|
||||
test('store post request validates platform is required', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms.0.platform');
|
||||
});
|
||||
|
||||
test('store post request validates content max length', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => str_repeat('a', 5001),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('platforms.0.content');
|
||||
});
|
||||
|
||||
test('store post request allows valid draft post', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Draft->value,
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
});
|
||||
|
||||
test('store post request allows valid scheduled post', function () {
|
||||
$response = $this->actingAs($this->user)->post(route('posts.store'), [
|
||||
'status' => PostStatus::Scheduled->value,
|
||||
'scheduled_at' => now()->addDay()->toISOString(),
|
||||
'platforms' => [
|
||||
[
|
||||
'social_account_id' => $this->socialAccount->id,
|
||||
'platform' => 'linkedin',
|
||||
'content' => 'Test content',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionHasNoErrors();
|
||||
});
|
||||
Loading…
Reference in a new issue