Skip to content

Commit

Permalink
remove api call from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Oct 16, 2024
1 parent aa392fd commit 31902b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IRoom } from '@rocket.chat/core-typings';
import {
Box,
Modal,
Expand Down Expand Up @@ -25,7 +26,6 @@ import {
useToastMessageDispatch,
usePermissionWithScopedRoles,
} from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ComponentProps, ReactElement } from 'react';
import React, { useEffect, useMemo } from 'react';
import { useForm, Controller } from 'react-hook-form';
Expand All @@ -37,6 +37,7 @@ import { useEncryptedRoomDescription } from '../hooks/useEncryptedRoomDescriptio

type CreateChannelModalProps = {
teamId?: string;
mainRoom?: IRoom;
onClose: () => void;
reload?: () => void;
};
Expand All @@ -62,7 +63,7 @@ const getFederationHintKey = (licenseModule: ReturnType<typeof useHasLicenseModu
return 'Federation_Matrix_Federated_Description';
};

const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModalProps): ReactElement => {
const CreateChannelModal = ({ teamId = '', mainRoom, onClose, reload }: CreateChannelModalProps): ReactElement => {
const t = useTranslation();
const canSetReadOnly = usePermissionWithScopedRoles('set-readonly', ['owner']);
const e2eEnabled = useSetting('E2E_Enable');
Expand All @@ -79,19 +80,12 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal
const federatedModule = useHasLicenseModule('federation');
const canUseFederation = federatedModule !== 'loading' && federatedModule && federationEnabled;

const teamsInfoEndpoint = useEndpoint('GET', '/v1/teams.info');
const channelNameExists = useEndpoint('GET', '/v1/rooms.nameExists');
const createChannel = useEndpoint('POST', '/v1/channels.create');
const createPrivateChannel = useEndpoint('POST', '/v1/groups.create');

const { data: teamInfoData } = useQuery(['teamId', teamId], async () => teamsInfoEndpoint({ teamId }), {
keepPreviousData: true,
retry: false,
enabled: teamId !== '',
});

const canCreateTeamChannel = usePermission('create-team-channel', teamInfoData?.teamInfo.roomId);
const canCreateTeamGroup = usePermission('create-team-group', teamInfoData?.teamInfo.roomId);
const canCreateTeamChannel = usePermission('create-team-channel', mainRoom?._id);
const canCreateTeamGroup = usePermission('create-team-group', mainRoom?._id);

const dispatchToastMessage = useToastMessageDispatch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TeamsChannelsWithData = () => {
});

const handleCreateNew = useEffectEvent(() => {
setModal(<CreateChannelWithData teamId={teamId} onClose={() => setModal(null)} reload={reload} />);
setModal(<CreateChannelWithData teamId={teamId} mainRoom={room} onClose={() => setModal(null)} reload={reload} />);
});

const goToRoom = useEffectEvent((room: IRoom) => {
Expand Down

0 comments on commit 31902b7

Please sign in to comment.