diff --git a/src/components/DialogAssetEdit/index.tsx b/src/components/DialogAssetEdit/index.tsx index ce2a7f44..01b33335 100644 --- a/src/components/DialogAssetEdit/index.tsx +++ b/src/components/DialogAssetEdit/index.tsx @@ -47,7 +47,7 @@ const DialogAssetEdit = (props: Props) => { const assetItem = useTypedSelector(state => selectAssetById(state, String(assetId))) // TODO: check casting const tags = useTypedSelector(selectTags) - const assetUpdatedPrev = useRef<string | null>(null) + const assetUpdatedPrev = useRef<string | undefined>(undefined) // Generate a snapshot of the current asset const [assetSnapshot, setAssetSnapshot] = useState(assetItem?.asset) @@ -222,7 +222,7 @@ const DialogAssetEdit = (props: Props) => { <FormSubmitButton disabled={formUpdating || !isDirty || !isValid} isValid={isValid} - lastUpdated={currentAsset._updatedAt} + lastUpdated={currentAsset?._updatedAt} onClick={handleSubmit(onSubmit)} /> </Flex> @@ -242,7 +242,7 @@ const DialogAssetEdit = (props: Props) => { */} <Flex direction={['column-reverse', 'column-reverse', 'row-reverse']}> <Box flex={1} marginTop={[5, 5, 0]} padding={4}> - <WithReferringDocuments documentStore={documentStore} id={assetItem.asset._id}> + <WithReferringDocuments documentStore={documentStore} id={currentAsset._id}> {({isLoading, referringDocuments}) => { const uniqueReferringDocuments = getUniqueDocuments(referringDocuments) return ( diff --git a/src/components/TableRowAsset/index.tsx b/src/components/TableRowAsset/index.tsx index fda28241..6a5000b3 100644 --- a/src/components/TableRowAsset/index.tsx +++ b/src/components/TableRowAsset/index.tsx @@ -100,6 +100,7 @@ const TableRowAsset = (props: Props) => { (e: MouseEvent<HTMLDivElement>) => { e.stopPropagation() + if (!asset) return if (onSelect) { dispatch(dialogActions.showAssetEdit({assetId: asset._id})) } else if (shiftPressed.current && !picked) { @@ -108,13 +109,14 @@ const TableRowAsset = (props: Props) => { dispatch(assetsActions.pick({assetId: asset._id, picked: !picked})) } }, - [asset._id, dispatch, lastPicked, onSelect, picked, shiftPressed] + [asset, dispatch, lastPicked, onSelect, picked, shiftPressed] ) const handleClick = useCallback( (e: MouseEvent<HTMLDivElement>) => { e.stopPropagation() + if (!asset) return if (onSelect) { onSelect([{kind: 'assetDocumentId', value: asset._id}]) } else if (shiftPressed.current) { @@ -127,7 +129,7 @@ const TableRowAsset = (props: Props) => { dispatch(dialogActions.showAssetEdit({assetId: asset._id})) } }, - [asset._id, dispatch, lastPicked, onSelect, picked, shiftPressed] + [asset, dispatch, lastPicked, onSelect, picked, shiftPressed] ) const opacityCell = updating ? 0.5 : 1 diff --git a/src/modules/assets/index.ts b/src/modules/assets/index.ts index 5817a63a..e77cdfc5 100644 --- a/src/modules/assets/index.ts +++ b/src/modules/assets/index.ts @@ -791,7 +791,10 @@ export const selectAssetById = createSelector( (state: RootReducerState) => state.assets.byIds, (_state: RootReducerState, assetId: string) => assetId ], - (byIds, assetId) => byIds[assetId] + (byIds, assetId) => { + const asset = byIds[assetId] + return asset ? asset : undefined + } ) export const selectAssets: Selector<RootReducerState, AssetItem[]> = createSelector(