11import { createSlice , PayloadAction } from '@reduxjs/toolkit' ;
22
3+ export interface ChatRoomsInfo {
4+ talentId : string ;
5+ roomId : string ;
6+ count : number ;
7+ otherId : string ;
8+ otherNickname : string ;
9+ profileImage : string ;
10+ clickPurchase : boolean [ ] ;
11+ otherIsJoined : boolean ;
12+ }
13+
314export interface UserState {
415 userInfo : {
516 id : string ;
617 social : string ;
718 nickname : string ;
819 image : string | undefined ;
920 email : string | undefined ;
10- selling : any ;
11- buying : any ;
12- unreviewed : any ;
13- reviewed : any ;
14- chatRooms : any ;
21+ selling ?: string [ ] ;
22+ buying ?: string [ ] ;
23+ unreviewed ?: string [ ] ;
24+ reviewed ?: string [ ] ;
25+ chatRooms ?: ChatRoomsInfo [ ] | undefined ;
1526 } | null ;
1627 accessToken : string | null ;
1728 isSignin ?: boolean ;
@@ -69,10 +80,10 @@ export const userSlice = createSlice({
6980 // ๊ตฌ๋งค์๊ฐ ๋ฆฌ๋ทฐ๋ฅผ ๋ฑ๋กํ๋ฉด unreviewed์ ์๋ talentId๋ฅผ reviewed๋ก ์ฎ๊ฒจ์ค๋ค.
7081 updateReview : ( state , action : PayloadAction < UpdateReviewPayload > ) => {
7182 const { talentId } = action . payload ;
72- if ( state . userInfo ) {
83+ if ( state . userInfo ?. unreviewed ) {
7384 const index = state . userInfo . unreviewed . indexOf ( talentId ) ;
74- state . userInfo . unreviewed . splice ( index , 1 ) ;
75- state . userInfo . reviewed . push ( talentId ) ;
85+ state . userInfo . unreviewed ? .splice ( index , 1 ) ;
86+ state . userInfo . reviewed ? .push ( talentId ) ;
7687 }
7788 } ,
7889
@@ -83,13 +94,13 @@ export const userSlice = createSlice({
8394 } ,
8495
8596 updateChatRooms : ( state , action : PayloadAction < UpdateChatRoomsPayload > ) => {
86- if ( state . userInfo ) {
87- state . userInfo . chatRooms . push ( action . payload . chatRooms ) ;
97+ if ( state . userInfo ?. chatRooms ) {
98+ state . userInfo . chatRooms ? .push ( action . payload . chatRooms ) ;
8899 }
89100 } ,
90101 renewChatRooms : ( state , action : PayloadAction < RenewChatRoomsPayload > ) => {
91102 console . log ( '๋ฆฌ๋์ค renewChatRooms ํ์ด๋ก๋:::::' , action . payload ) ;
92- if ( state . userInfo ) {
103+ if ( state . userInfo ?. chatRooms ) {
93104 state . userInfo . chatRooms = action . payload . chatRooms ;
94105 }
95106 } ,
@@ -98,8 +109,8 @@ export const userSlice = createSlice({
98109 // ๊ฑฐ๋์๋ฃ๋ฒํผ์ ๋๋ ์๋ ์๋ฒ์์ confirmed๋ฅผ boolean๊ฐ์ผ๋ก ์ค๋ค.
99110
100111 const { roomId, who, talentId } = action . payload ;
101- if ( state . userInfo ) {
102- const roomIndex = state . userInfo . chatRooms . findIndex ( ( room : any ) => room . roomId === roomId ) ;
112+ if ( state . userInfo ?. chatRooms && state . userInfo ?. buying && state . userInfo ?. unreviewed ) {
113+ const roomIndex = state . userInfo . chatRooms ? .findIndex ( ( room : any ) => room . roomId === roomId ) ;
103114
104115 const { clickPurchase } = state . userInfo . chatRooms [ roomIndex ] ;
105116 if ( who === 'mine' ) {
@@ -136,7 +147,7 @@ export const userSlice = createSlice({
136147
137148 escapeRoom : ( state , action : PayloadAction < { talentId : string } > ) => {
138149 const { talentId } = action . payload ;
139- if ( state . userInfo ) {
150+ if ( state . userInfo ?. buying && state . userInfo ?. chatRooms ) {
140151 // ๋๊ฐ ๋ฐฉ๊ณผ ์ผ์นํ๋ ๊ตฌ๋งค์ค๋ชฉ๋ก์ talentId๋ฅผ ์์ ์ค๋ค.
141152 const buyingIndex = state . userInfo . buying . indexOf ( talentId ) ;
142153 state . userInfo . buying . splice ( buyingIndex , 1 ) ;
@@ -148,7 +159,7 @@ export const userSlice = createSlice({
148159 } ,
149160 initCount : ( state , action : PayloadAction < { index : number } > ) => {
150161 const { index } = action . payload ;
151- if ( state . userInfo ) {
162+ if ( state . userInfo ?. chatRooms ) {
152163 console . log ( 'roomindex::::' , index ) ;
153164 state . userInfo . chatRooms [ index ] . count = 0 ;
154165 }
0 commit comments