Save the autofilled site logo as the workspace logo on brand settings update
Brand autofill on the workspace settings page already captured the site logo and rendered a preview beneath the URL, but the update flow never persisted it. The store flow attached it via LogoAttacher; the update flow was missing all three legs: the form field, the request rule, and the controller attach. - BrandTab: add logo_url to the useForm payload so autofill can set it and the form submits it. - UpdateWorkspaceRequest: validate logo_url (nullable url) — FormRequest strips any unvalidated key, so without a rule it was silently dropped. - WorkspaceController::updateSettings: pull logo_url out of the validated data (it is not a column) and attach it through LogoAttacher, mirroring store.
This commit is contained in:
parent
6f13e2c8b4
commit
b7773849ec
4 changed files with 44 additions and 2 deletions
|
|
@ -198,7 +198,7 @@ public function deleteLogo(Request $request): RedirectResponse
|
|||
return back()->with('flash.success', __('settings.flash.logo_deleted'));
|
||||
}
|
||||
|
||||
public function updateSettings(UpdateWorkspaceRequest $request): RedirectResponse
|
||||
public function updateSettings(UpdateWorkspaceRequest $request, LogoAttacher $logoAttacher): RedirectResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$workspace = $user->currentWorkspace;
|
||||
|
|
@ -209,7 +209,24 @@ public function updateSettings(UpdateWorkspaceRequest $request): RedirectRespons
|
|||
|
||||
$this->authorize('update', $workspace);
|
||||
|
||||
$workspace->update($request->validated());
|
||||
$validated = $request->validated();
|
||||
|
||||
$logoUrl = data_get($validated, 'logo_url');
|
||||
unset($validated['logo_url']);
|
||||
|
||||
$workspace->update($validated);
|
||||
|
||||
if ($logoUrl) {
|
||||
try {
|
||||
$logoAttacher->attach($workspace, $logoUrl);
|
||||
} catch (Throwable $e) {
|
||||
Log::warning('Logo attach failed during workspace update', [
|
||||
'workspace_id' => $workspace->id,
|
||||
'logo_url' => $logoUrl,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return back()->with('flash.success', __('settings.flash.workspace_updated'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public function rules(): array
|
|||
'brand_font' => ['sometimes', 'required', 'string', Rule::in(BrandFont::values())],
|
||||
'image_style' => ['sometimes', 'required', 'string', Rule::in(ImageStyle::values())],
|
||||
'content_language' => ['sometimes', 'string', Rule::in(ContentLanguage::values())],
|
||||
'logo_url' => ['nullable', 'url', 'max:1024'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ const form = useForm({
|
|||
brand_font: props.workspace.brand_font ?? 'Inter',
|
||||
image_style: props.workspace.image_style ?? 'cinematic',
|
||||
content_language: props.workspace.content_language ?? 'en',
|
||||
logo_url: '' as string | null,
|
||||
});
|
||||
|
||||
const submit = () => {
|
||||
|
|
|
|||
|
|
@ -697,3 +697,26 @@
|
|||
'logo_url' => 'https://example.com/logo.png',
|
||||
])->assertRedirect();
|
||||
});
|
||||
|
||||
test('update settings attaches the autofilled logo when logo_url is provided', function () {
|
||||
$logoAttacher = $this->mock(LogoAttacher::class);
|
||||
$logoAttacher->shouldReceive('attach')->once();
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->from(route('app.workspace.brand'))
|
||||
->put(route('app.workspace.settings.update'), [
|
||||
'name' => $this->workspace->name,
|
||||
'logo_url' => 'https://example.com/logo.png',
|
||||
])->assertRedirect(route('app.workspace.brand'))
|
||||
->assertSessionHasNoErrors();
|
||||
});
|
||||
|
||||
test('update settings does not touch the logo when no logo_url is provided', function () {
|
||||
$logoAttacher = $this->mock(LogoAttacher::class);
|
||||
$logoAttacher->shouldReceive('attach')->never();
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->put(route('app.workspace.settings.update'), [
|
||||
'name' => $this->workspace->name,
|
||||
])->assertRedirect();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue