import React, { useEffect, useState } from 'react' import { usePage } from '@inertiajs/react' import StudioLayout from '../../Layouts/StudioLayout' import { studioSurface, trackStudioEvent } from '../../utils/studioEvents' const shortcutOptions = [ { value: '/dashboard/profile', label: 'Dashboard profile' }, { value: '/dashboard/notifications', label: 'Notifications' }, { value: '/dashboard/comments/received', label: 'Received comments' }, { value: '/dashboard/followers', label: 'Followers' }, { value: '/dashboard/following', label: 'Following' }, { value: '/dashboard/favorites', label: 'Favorites' }, { value: '/dashboard/artworks', label: 'Artwork dashboard' }, { value: '/dashboard/gallery', label: 'Gallery' }, { value: '/dashboard/awards', label: 'Awards' }, { value: '/creator/stories', label: 'Story dashboard' }, { value: '/studio', label: 'Creator Studio' }, ] const widgetOptions = [ { value: 'quick_stats', label: 'Quick stats' }, { value: 'continue_working', label: 'Continue working' }, { value: 'scheduled_items', label: 'Scheduled items' }, { value: 'recent_activity', label: 'Recent activity' }, { value: 'top_performers', label: 'Top performers' }, { value: 'draft_reminders', label: 'Draft reminders' }, { value: 'module_summaries', label: 'Module summaries' }, { value: 'growth_hints', label: 'Growth hints' }, { value: 'active_challenges', label: 'Active challenges' }, { value: 'creator_health', label: 'Creator health' }, { value: 'featured_status', label: 'Featured status' }, { value: 'comments_snapshot', label: 'Comments snapshot' }, { value: 'stale_drafts', label: 'Stale drafts' }, ] const landingOptions = [ ['overview', 'Overview'], ['content', 'Content'], ['drafts', 'Drafts'], ['scheduled', 'Scheduled'], ['calendar', 'Calendar'], ['inbox', 'Inbox'], ['analytics', 'Analytics'], ['growth', 'Growth'], ['challenges', 'Challenges'], ['search', 'Search'], ['preferences', 'Preferences'], ] async function requestJson(url, method, body) { const response = await fetch(url, { method, credentials: 'same-origin', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.getAttribute('content') || '', 'X-Requested-With': 'XMLHttpRequest', }, body: body ? JSON.stringify(body) : undefined, }) const payload = await response.json().catch(() => ({})) if (!response.ok) { throw new Error(payload?.message || payload?.error || 'Request failed') } return payload } export default function StudioPreferences() { const { props } = usePage() const preferences = props.preferences || {} const [form, setForm] = useState({ default_content_view: preferences.default_content_view || 'grid', analytics_range_days: preferences.analytics_range_days || 30, dashboard_shortcuts: preferences.dashboard_shortcuts || [], draft_behavior: preferences.draft_behavior || 'resume-last', default_landing_page: preferences.default_landing_page || 'overview', widget_visibility: preferences.widget_visibility || {}, widget_order: preferences.widget_order || widgetOptions.map((option) => option.value), card_density: preferences.card_density || 'comfortable', scheduling_timezone: preferences.scheduling_timezone || '', }) const [saving, setSaving] = useState(false) useEffect(() => { setForm({ default_content_view: preferences.default_content_view || 'grid', analytics_range_days: preferences.analytics_range_days || 30, dashboard_shortcuts: preferences.dashboard_shortcuts || [], draft_behavior: preferences.draft_behavior || 'resume-last', default_landing_page: preferences.default_landing_page || 'overview', widget_visibility: preferences.widget_visibility || {}, widget_order: preferences.widget_order || widgetOptions.map((option) => option.value), card_density: preferences.card_density || 'comfortable', scheduling_timezone: preferences.scheduling_timezone || '', }) }, [preferences]) const toggleShortcut = (value) => { setForm((current) => ({ ...current, dashboard_shortcuts: current.dashboard_shortcuts.includes(value) ? current.dashboard_shortcuts.filter((entry) => entry !== value) : [...current.dashboard_shortcuts, value].slice(0, 8), })) } const toggleWidget = (value) => { setForm((current) => ({ ...current, widget_visibility: { ...current.widget_visibility, [value]: !(current.widget_visibility?.[value] !== false), }, })) } const moveWidget = (value, direction) => { setForm((current) => { const items = [...current.widget_order] const index = items.indexOf(value) if (index < 0) return current const nextIndex = direction === 'up' ? index - 1 : index + 1 if (nextIndex < 0 || nextIndex >= items.length) return current const swapped = items[nextIndex] items[nextIndex] = value items[index] = swapped trackStudioEvent('studio_widget_reordered', { surface: studioSurface(), module: 'preferences', meta: { widget: value, direction, from: index + 1, to: nextIndex + 1, }, }) return { ...current, widget_order: items } }) } const saveSettings = async () => { setSaving(true) try { await requestJson(props.endpoints.save, 'PUT', form) window.alert('Studio preferences saved.') } catch (error) { window.alert(error?.message || 'Unable to save Studio preferences.') } finally { setSaving(false) } } return (

Workspace preferences

Choose where Studio opens, how dense content cards feel, and which overview modules stay visible.

Dashboard shortcuts

Pin up to 8 destinations that should stay easy to reach from the wider workspace.

{form.dashboard_shortcuts.length}/8 selected
{shortcutOptions.map((option) => { const active = form.dashboard_shortcuts.includes(option.value) return ( ) })}

Overview widgets

Show, hide, and prioritize dashboard sections for your daily workflow.

{form.widget_order.map((widgetKey, index) => { const option = widgetOptions.find((entry) => entry.value === widgetKey) if (!option) return null const enabled = form.widget_visibility?.[widgetKey] !== false return (
{option.label}
Position {index + 1}
) })}

Related surfaces

{(props.links || []).map((link) => (
{link.label}
))}

Preference notes

Landing page and widget order are stored in the shared Studio preference record, so new Creator Studio surfaces can plug into the same contract without another migration.
Analytics range and card density stay here so Analytics, Growth, and the main dashboard can stay visually consistent.
) }