import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import type { UserTraits } from '../types' ; import { getUUID } from '../uuid' ; export type UserInfoState = { anonymousId : string ; userId ? : string ; traits ? : UserTraits ; } ; export const initialState = { anonymousId : getUUID ( ) , } ; export default createSlice ( { name : 'userInfo' , initialState , reducers : { reset : ( ) => ( { anonymousId : getUUID ( ) , userId : undefined , traits : undefined , } ) , setUserId : ( state , action ) => { state . userId = action . payload . userId ; } , setTraits : ( state , action ) => { state . traits = { ... action . payload . traits , } ; } , setAnonymousId : ( state , action ) => { state . anonymousId = action . payload . anonymousId ; } , } , } ) ;