diff --git a/webapp/src/api.ts b/webapp/src/api.ts index 039280e..47b5ee3 100644 --- a/webapp/src/api.ts +++ b/webapp/src/api.ts @@ -77,7 +77,7 @@ string | FetchArgs, unknown, FetchBaseQueryError > = async (args, api, extraOptions) => { - const baseUrl = getPluginServerRoute(api.getState()) + const baseUrl = getPluginServerRoute(api.getState() as any) const adjustedArgs = typeof args === 'string' ? { url: joinUrl(baseUrl, args), diff --git a/webapp/src/components/push_reflection/push_reflection_button.tsx b/webapp/src/components/push_reflection/push_reflection_button.tsx deleted file mode 100644 index 6bf7079..0000000 --- a/webapp/src/components/push_reflection/push_reflection_button.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react' -import {useSelector} from 'react-redux' - -import {getAssetsUrl} from '../../selectors' - -const PushReflectionButton = (props) => { - console.log('PushReflectionButton', props) - const assetsPath = useSelector(getAssetsUrl) - - const handleClick = () => { - console.log('Push Reflection Button clicked') - } - - return ( - - ) -} - -export default PushReflectionButton diff --git a/webapp/src/components/push_reflection/push_reflection_modal.tsx b/webapp/src/components/push_reflection/push_reflection_modal.tsx index e8e51f3..5a05e54 100644 --- a/webapp/src/components/push_reflection/push_reflection_modal.tsx +++ b/webapp/src/components/push_reflection/push_reflection_modal.tsx @@ -5,16 +5,18 @@ import {useDispatch, useSelector} from 'react-redux' import {getPost} from 'mattermost-redux/selectors/entities/posts' +import {GlobalState} from 'mattermost-redux/types/store' + import {useCreateReflectionMutation, useGetActiveMeetingsQuery} from '../../api' import {closePushPostAsReflection} from '../../reducers' import {getAssetsUrl, getPostURL, pushPostAsReflection} from '../../selectors' -const PostUtils = window.PostUtils +const PostUtils = (window as any).PostUtils const PushReflectionModal = () => { const postId = useSelector(pushPostAsReflection) - const post = useSelector((state) => getPost(state, postId)) - const postUrl = useSelector((state) => getPostURL(state, postId)) + const post = useSelector((state: GlobalState) => getPost(state, postId!)) + const postUrl = useSelector((state: GlobalState) => getPostURL(state, postId!)) const {data, isLoading, refetch} = useGetActiveMeetingsQuery() useEffect(() => { diff --git a/webapp/src/index.tsx b/webapp/src/index.tsx index 9f65cb7..01df1db 100644 --- a/webapp/src/index.tsx +++ b/webapp/src/index.tsx @@ -1,10 +1,10 @@ import React from 'react' import {Store, AnyAction} from 'redux' -import {GlobalState} from '@mattermost/types/lib/store' - import {setupListeners} from '@reduxjs/toolkit/query' +import {GlobalState} from 'mattermost-redux/types/store' + import manifest from '@/manifest' import {PluginRegistry} from '@/types/mattermost-webapp' diff --git a/webapp/src/reducers.ts b/webapp/src/reducers.ts index 622d8c8..15d36b5 100644 --- a/webapp/src/reducers.ts +++ b/webapp/src/reducers.ts @@ -1,4 +1,4 @@ -import {createSlice, PayloadAction} from '@reduxjs/toolkit' +import {AnyAction, createSlice, PayloadAction} from '@reduxjs/toolkit' import {api} from './api' @@ -31,7 +31,9 @@ export const { closePushPostAsReflection, } = localSlice.actions -const rootReducer = (state, action) => { +export type PluginState = ReturnType & ReturnType + +const rootReducer = (state: PluginState, action: AnyAction) => { const apiState = api.reducer(state, action) const localState = localSlice.reducer(state, action) return { diff --git a/webapp/src/selectors.ts b/webapp/src/selectors.ts index 9349c57..9baf842 100644 --- a/webapp/src/selectors.ts +++ b/webapp/src/selectors.ts @@ -1,33 +1,37 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general' import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams' +import {GlobalState} from 'mattermost-redux/types/store' + import manifest from '@/manifest' +import {PluginState} from './reducers' + const {id} = manifest -export const getSiteURL = (state) => { +export const getSiteURL = (state: GlobalState) => { const config = getConfig(state) return config?.SiteURL ?? '' } -export const getCurrentTeamURL = (state) => { +export const getCurrentTeamURL = (state: GlobalState) => { const siteURL = getSiteURL(state) const team = getCurrentTeam(state) return `${siteURL}/${team?.name ?? ''}` } -export const getPostURL = (state, postId) => { +export const getPostURL = (state: GlobalState, postId: string) => { const teamURL = getCurrentTeamURL(state) return `${teamURL}/pl/${postId}` } -export const getPluginRoot = (state) => { +export const getPluginRoot = (state: GlobalState) => { const config = getConfig(state) const siteURL = config?.SiteURL ?? '' return `${siteURL}/plugins/${id}` } -export const getPluginServerRoute = (state) => { +export const getPluginServerRoute = (state: GlobalState) => { let basePath = '' const config = getConfig(state) const siteURL = config?.SiteURL ?? '' @@ -42,17 +46,15 @@ export const getPluginServerRoute = (state) => { return `${basePath}/plugins/${id}` } -export const getAssetsUrl = (state) => { +export const getAssetsUrl = (state: GlobalState) => { const siteURL = getPluginRoot(state) return `${siteURL}/public` } -export const getPluginState = (state) => state[`plugins-${id}`] ?? {} - -export const meetingTemplates = (state) => getPluginState(state).meetingTemplates +export const getPluginState = (state: GlobalState) => ((state as any)[`plugins-${id}`] ?? {}) as PluginState -export const isStartActivityModalVisible = (state) => getPluginState(state).isStartActivityModalVisible +export const isStartActivityModalVisible = (state: GlobalState) => getPluginState(state).isStartActivityModalVisible -export const pushPostAsReflection = (state) => getPluginState(state).pushPostAsReflection +export const pushPostAsReflection = (state: GlobalState) => getPluginState(state).pushPostAsReflection //export const get