feat: aggiunta salvataggio impostazioni profilo dinamico user name e email
This commit is contained in:
@@ -15,6 +15,11 @@ type SettingsSnapshot = {
|
||||
subscriptionState: SubscriptionState
|
||||
}
|
||||
|
||||
type ProfileIdentity = {
|
||||
username: string
|
||||
email: string
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'briefai-settings'
|
||||
const ONBOARDING_KEY = 'briefai-onboarding'
|
||||
const DEFAULT_MACRO_TOPICS = ['Scienza & Ricerca']
|
||||
@@ -62,6 +67,10 @@ function persistSettings(snapshot: SettingsSnapshot) {
|
||||
// Pagina Impostazioni: gestisce preferenze feed e account con una struttura a tab.
|
||||
function SettingsPage() {
|
||||
const [activeTab, setActiveTab] = useState<SettingsTab>('interests')
|
||||
const [profileIdentity, setProfileIdentity] = useState<ProfileIdentity>({
|
||||
username: '',
|
||||
email: '',
|
||||
})
|
||||
const [selectedMacroTopics, setSelectedMacroTopics] = useState<string[]>(() =>
|
||||
readInitialSettings().selectedMacroTopics,
|
||||
)
|
||||
@@ -75,6 +84,10 @@ function SettingsPage() {
|
||||
fetchProfile()
|
||||
.then((res) => {
|
||||
if (res && res.profile) {
|
||||
setProfileIdentity({
|
||||
username: res.profile.username || '',
|
||||
email: res.profile.email || '',
|
||||
})
|
||||
setSelectedMacroTopics(res.profile.macroTopics || [])
|
||||
setKeywords(res.profile.keywords || [])
|
||||
}
|
||||
@@ -182,8 +195,8 @@ function SettingsPage() {
|
||||
</div>
|
||||
) : (
|
||||
<AccountSettings
|
||||
username="John Doe"
|
||||
email="john@example.com"
|
||||
username={profileIdentity.username || 'Utente'}
|
||||
email={profileIdentity.email || 'Email non disponibile'}
|
||||
subscriptionState={subscriptionState}
|
||||
onUpgrade={handleUpgrade}
|
||||
onCancelSubscription={handleCancelSubscription}
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
const BASE = import.meta.env.VITE_API_URL as string
|
||||
import { getAuthHeader } from './authService'
|
||||
|
||||
export type ProfileResponse = {
|
||||
success?: boolean
|
||||
profile?: {
|
||||
userId?: string
|
||||
username?: string
|
||||
email?: string
|
||||
macroTopics?: string[]
|
||||
keywords?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
const authFetch = (path: string, options: RequestInit = {}) =>
|
||||
fetch(`${BASE}${path}`, {
|
||||
...options,
|
||||
@@ -29,7 +40,7 @@ export const fetchOverview = () =>
|
||||
|
||||
// GET /api/profile
|
||||
export const fetchProfile = () =>
|
||||
authFetch('/api/profile').then((r) => r.json())
|
||||
authFetch('/api/profile').then((r) => r.json() as Promise<ProfileResponse>)
|
||||
|
||||
// PUT /api/profile
|
||||
export const updateProfile = async (data: {
|
||||
|
||||
Reference in New Issue
Block a user