@@ -7,7 +7,7 @@ import CreateTeamTypeFormModal from './CreateTeamTypeFormModal';
77import { TeamType } from 'shared' ;
88import EditTeamTypeFormModal from './EditTeamTypeFormModal' ;
99import { useAllTeamTypes , useSetTeamTypeImage } from '../../../hooks/team-types.hooks' ;
10- import { useMemo , useState } from 'react' ;
10+ import { useState } from 'react' ;
1111import { useToast } from '../../../hooks/toasts.hooks' ;
1212import NERUploadButton from '../../../components/NERUploadButton' ;
1313import { useGetImageUrls } from '../../../hooks/onboarding.hook' ;
@@ -25,28 +25,31 @@ const TeamTypeTable: React.FC = () => {
2525 const [ addedImages , setAddedImages ] = useState < { [ key : string ] : File | undefined } > ( { } ) ;
2626 const toast = useToast ( ) ;
2727
28- const imageFileIds = teamTypes ?. map ( ( teamType ) => teamType . imageFileId ) ?? [ ] ;
29- const { data : imageUrlsList , isLoading, isError } = useGetImageUrls ( imageFileIds ) ;
30- const { mutateAsync : setTeamTypeImage , isLoading : setTeamTypeIsLoading } = useSetTeamTypeImage ( ) ;
31-
32- const imageUrls = useMemo ( ( ) => {
33- if ( ! imageUrlsList || isLoading || isError ) return { } ;
28+ const teamTypeImageList =
29+ teamTypes ?. map ( ( teamType ) => {
30+ return { objectId : teamType . teamTypeId , imageFileId : teamType . imageFileId } ;
31+ } ) ?? [ ] ;
3432
35- const urlMap : { [ key : string ] : string | undefined } = { } ;
36- teamTypes ?. forEach ( ( teamType , index ) => {
37- urlMap [ teamType . teamTypeId ] = imageUrlsList [ index ] ;
38- } ) ;
39- return urlMap ;
40- } , [ imageUrlsList , isLoading , isError , teamTypes ] ) ;
33+ const { data : imageUrlsList , isLoading, isError, error } = useGetImageUrls ( teamTypeImageList ) ;
34+ const { mutateAsync : setTeamTypeImage , isLoading : setTeamTypeIsLoading } = useSetTeamTypeImage ( ) ;
4135
4236 if ( teamTypesIsError ) {
4337 return < ErrorPage message = { teamTypesError ?. message } /> ;
4438 }
4539
46- if ( ! teamTypes || teamTypesIsLoading || setTeamTypeIsLoading ) {
40+ if ( isError ) {
41+ return < ErrorPage message = { error ?. message } /> ;
42+ }
43+
44+ if ( ! teamTypes || teamTypesIsLoading || setTeamTypeIsLoading || ! imageUrlsList || isLoading ) {
4745 return < LoadingIndicator /> ;
4846 }
4947
48+ const imageUrlsMap : { [ key : string ] : string | undefined } = { } ;
49+ imageUrlsList . forEach ( ( item ) => {
50+ imageUrlsMap [ item . id ] = item . url ;
51+ } ) ;
52+
5053 const onSubmitTeamTypeImage = async ( teamTypeId : string ) => {
5154 const addedImage = addedImages [ teamTypeId ] ;
5255 if ( addedImage ) {
@@ -78,6 +81,7 @@ const TeamTypeTable: React.FC = () => {
7881 } ;
7982
8083 const teamTypesTableRows = teamTypes . map ( ( teamType ) => {
84+ console . log ( 'teamType' , teamType ) ;
8185 return (
8286 < TableRow >
8387 < TableCell onClick = { ( ) => setEditingTeamType ( teamType ) } sx = { { cursor : 'pointer' , border : '2px solid black' } } >
@@ -96,7 +100,12 @@ const TeamTypeTable: React.FC = () => {
96100 </ TableCell >
97101 < TableCell
98102 onClick = { ( ) => setEditingTeamType ( teamType ) }
99- sx = { { cursor : 'pointer' , border : '2px solid black' , verticalAlign : 'middle' } }
103+ sx = { {
104+ cursor : 'pointer' ,
105+ border : '2px solid black' ,
106+ verticalAlign : 'middle' ,
107+ maxWidth : '15vw'
108+ } }
100109 >
101110 < Box sx = { { display : 'flex' , alignItems : 'center' } } >
102111 < Typography variant = "body1" sx = { { marginLeft : 1 } } >
@@ -109,7 +118,7 @@ const TeamTypeTable: React.FC = () => {
109118 { teamType . imageFileId && ! addedImages [ teamType . teamTypeId ] && (
110119 < Box
111120 component = "img"
112- src = { imageUrls [ teamType . teamTypeId ] }
121+ src = { imageUrlsMap [ teamType . teamTypeId ] }
113122 alt = "Image Preview"
114123 sx = { { maxWidth : '100px' , mt : 1 , mb : 1 } }
115124 />
0 commit comments