Skip to content

Commit

Permalink
[MI-3831]: Update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
SaurabhSharma-884 committed Dec 14, 2023
1 parent 7e92ba4 commit 606c6d5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ export const LinkChannelModal = ({onClose}: {onClose: () => void}) => {
const {state} = usePluginApi();
const {show = false, isLoading} = getLinkModalState(state);
const currentTeam = getCurrentTeam(state);
const [mMChannel, setMmChannel] = useState<Channel | null>(null);
const [mSTeam, setMsTeam] = useState<MSTeamOrChannel | null>(null);
const [mSChannel, setMsChannel] = useState<MSTeamOrChannel | null>(null);
const [mmChannel, setMMChannel] = useState<MMTeamOrChannel | null>(null);
const [msTeam, setMSTeam] = useState<MSTeamOrChannel | null>(null);
const [msChannel, setMSChannel] = useState<MSTeamOrChannel | null>(null);

const handleModalClose = () => {
setMmChannel(null);
setMsTeam(null);
setMsChannel(null);
setMMChannel(null);
setMSTeam(null);
setMSChannel(null);
onClose();
};

return (
<Modal
show={show}
title='Link a channel'
subtitle='Link a channel in Mattermost with a channel in Microsoft Teams.'
subtitle='Link a channel in Mattermost with a channel in Microsoft Teams'
primaryActionText='Link Channels'
secondaryActionText='Cancel'
onFooterCloseHandler={handleModalClose}
onHeaderCloseHandler={handleModalClose}
isPrimaryButtonDisabled={!mMChannel || !mSChannel || !mSTeam}
isPrimaryButtonDisabled={!mmChannel || !msChannel || !msTeam}
onSubmitHandler={() => {
// TODO: handle channel linking
}}
>
{isLoading && <LinearProgress className='fixed w-full left-0 top-100'/>}
<SearchMMChannels
setChannel={setMmChannel}
setChannel={setMMChannel}
teamId={currentTeam}
/>
<hr className='w-full my-32'/>
<SearchMSTeams setMsTeam={setMsTeam}/>
<SearchMSTeams setMSTeam={setMSTeam}/>
<SearchMSChannels
setChannel={setMsChannel}
teamId={mSTeam?.ID}
setChannel={setMSChannel}
teamId={msTeam?.ID}
/>
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ export const SearchMMChannels = ({
setSuggestionsLoading(false);
dispatch(setLinkModalLoading(false));
}).catch((err) => {
// TODO: Handle error here
setSuggestionsLoading(false);
dispatch(setLinkModalLoading(true));
dispatch(setLinkModalLoading(false));
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SearchMMChannelProps = {
setChannel: React.Dispatch<React.SetStateAction<Channel | null>>;
setChannel: React.Dispatch<React.SetStateAction<MMTeamOrChannel | null>>;
teamId: string | null,
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@ export const SearchMSChannels = ({setChannel, teamId}: SearchMSChannelProps) =>
optionsLoading={searchSuggestionsLoading}
disabled={!teamId}
/>
</div>);
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import usePluginApi from 'hooks/usePluginApi';
import utils from 'utils';
import {setLinkModalLoading} from 'reducers/linkModal';

export const SearchMSTeams = ({setMsTeam}: {setMsTeam: React.Dispatch<React.SetStateAction<MSTeamOrChannel | null>>}) => {
export const SearchMSTeams = ({setMSTeam}: {setMSTeam: React.Dispatch<React.SetStateAction<MSTeamOrChannel | null>>}) => {
const dispatch = useDispatch();
const {makeApiRequestWithCompletionStatus, getApiState} = usePluginApi();
const [searchTerm, setSearchTerm] = useState<string>('');
const [searchTeamsPayload, setSearchTeamsPayload] = useState<SearchLinkedChannelParams | null>(null);
const [searchTeamsPayload, setSearchTeamsPayload] = useState<SearchParams | null>(null);
const [searchSuggestions, setSearchSuggestions] = useState<ListItemType[]>([]);

const searchTeams = ({searchFor}: {searchFor?: string}) => {
Expand All @@ -37,14 +37,14 @@ export const SearchMSTeams = ({setMsTeam}: {setMsTeam: React.Dispatch<React.SetS
const handleSearch = (val: string) => {
if (!val) {
setSearchSuggestions([]);
setMsTeam(null);
setMSTeam(null);
}
setSearchTerm(val);
debouncedSearchTeams({searchFor: val});
};

const handleTeamSelect = (_: any, option: ListItemType) => {
setMsTeam({
setMSTeam({
ID: option.value,
DisplayName: option.label as string,
});
Expand All @@ -53,14 +53,14 @@ export const SearchMSTeams = ({setMsTeam}: {setMsTeam: React.Dispatch<React.SetS

const handleClearInput = () => {
setSearchTerm('');
setMsTeam(null);
setMSTeam(null);
setSearchSuggestions([]);
};

const {data: searchedTeams, isLoading: searchSuggestionsLoading} = getApiState(pluginApiServiceConfigs.searchMSTeams.apiServiceName, searchTeamsPayload as SearchLinkedChannelParams);
const {data: searchedTeams, isLoading: searchSuggestionsLoading} = getApiState(pluginApiServiceConfigs.searchMSTeams.apiServiceName, searchTeamsPayload as SearchParams);
useApiRequestCompletionState({
serviceName: pluginApiServiceConfigs.searchMSTeams.apiServiceName,
payload: searchTeamsPayload as SearchLinkedChannelParams,
payload: searchTeamsPayload as SearchParams,
handleSuccess: () => {
if (searchedTeams) {
const suggestions: ListItemType[] = [];
Expand Down Expand Up @@ -89,7 +89,7 @@ export const SearchMSTeams = ({setMsTeam}: {setMsTeam: React.Dispatch<React.SetS
</div>
<MMSearch
fullWidth={true}
label='Select a team in Microsoft Teams '
label='Select a team in Microsoft Teams'
items={searchSuggestions}
onSelect={handleTeamSelect}
searchValue={searchTerm}
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/containers/Rhs/Rhs.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Rhs = () => {
page: defaultPage,
per_page: defaultPerPage,
});
const [getLinkedChannelsParams, setGetLinkedChannelsParams] = useState<SearchLinkedChannelParams | null>({...paginationQueryParams});
const [getLinkedChannelsParams, setGetLinkedChannelsParams] = useState<SearchParams | null>({...paginationQueryParams});
const {connected, msteamsUserId, username, isAlreadyConnected} = getConnectedState(state);
const [searchLinkedChannelsText, setSearchLinkedChannelsText] = useState('');
const [firstRender, setFirstRender] = useState(true);
Expand Down Expand Up @@ -78,7 +78,7 @@ export const Rhs = () => {
const {isOpen} = getSnackbarState(state);
const {data} = getApiState(pluginApiServiceConfigs.whitelistUser.apiServiceName);
const {presentInWhitelist} = data as WhitelistUserResponse;
const {data: linkedChannels, isLoading} = getApiState(pluginApiServiceConfigs.getLinkedChannels.apiServiceName, getLinkedChannelsParams as SearchLinkedChannelParams);
const {data: linkedChannels, isLoading} = getApiState(pluginApiServiceConfigs.getLinkedChannels.apiServiceName, getLinkedChannelsParams as SearchParams);

// Handle searching of linked channels with debounce
useEffect(() => {
Expand All @@ -98,7 +98,7 @@ export const Rhs = () => {

// Make api call to get linked channels
useEffect(() => {
const linkedChannelsParams: SearchLinkedChannelParams = {page: paginationQueryParams.page, per_page: paginationQueryParams.per_page};
const linkedChannelsParams: SearchParams = {page: paginationQueryParams.page, per_page: paginationQueryParams.per_page};
if (searchLinkedChannelsText) {
linkedChannelsParams.search = searchLinkedChannelsText;
}
Expand All @@ -118,7 +118,7 @@ export const Rhs = () => {
// Update total linked channels after completion of the api to get linked channels
useApiRequestCompletionState({
serviceName: pluginApiServiceConfigs.getLinkedChannels.apiServiceName,
payload: getLinkedChannelsParams as SearchLinkedChannelParams,
payload: getLinkedChannelsParams as SearchParams,
handleSuccess: () => {
if (linkedChannels) {
setTotalLinkedChannels([...totalLinkedChannels, ...(linkedChannels as ChannelLinkData[])]);
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const msTeamsPluginApi = createApi({
responseHandler: (res) => res.text(),
}),
}),
[pluginApiServiceConfigs.searchMSTeams.apiServiceName]: builder.query<MSTeamsSearchResponse, SearchLinkedChannelParams>({
[pluginApiServiceConfigs.searchMSTeams.apiServiceName]: builder.query<MSTeamsSearchResponse, SearchParams>({
query: (params) => ({
url: pluginApiServiceConfigs.searchMSTeams.path,
method: pluginApiServiceConfigs.searchMSTeams.method,
Expand Down
7 changes: 1 addition & 6 deletions webapp/src/types/common/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@ type ChannelLinkData = {
mattermostChannelType: string,
}

type Team = {
type MMTeamOrChannel = {
id: string,
displayName: string,
}

type Channel = Team & {
type?: 'public' | 'private';
}

type MSTeamOrChannel = {
ID: string,
DisplayName: string,
}

type MSTeamsSearchResponse = MSTeamOrChannel[];

4 changes: 2 additions & 2 deletions webapp/src/types/common/payload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ type UnlinkChannelParams = {
channelId: string;
}

type SearchLinkedChannelParams = PaginationQueryParams & {
type SearchParams = PaginationQueryParams & {
search?: string;
}

type SearchMSChannelsParams = SearchLinkedChannelParams & {
type SearchMSChannelsParams = SearchParams & {
teamId: string;
}
2 changes: 1 addition & 1 deletion webapp/src/types/common/service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ type APIError = {
message: string,
}

type APIRequestPayload = SearchLinkedChannelParams | void;
type APIRequestPayload = SearchParams | void;

0 comments on commit 606c6d5

Please sign in to comment.