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