-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge teams frontend changes to the backend branch (#21190)
* add folder structure * Create ChannelAutoCompleteMultiple component * Create GenericModal with Variants * remove enum * [WIP] Create Team Modal * add pagination prop to GenericTable * create teams modal * remove ChannelAutoCompleteMultiple component * set description in team * fix redirect to room * remove braces from simple string Co-authored-by: Tasso Evangelista <[email protected]> * single coat instead bool * refactor useReactModal * Move CreateTeam module * Split TeamNameInput * Convert BaseAvatar and UserAvatar to TypeScript * Add UsersInput * Convert CreateTeamModal to TypeScript * Upgrade Fuselage * update generic modal * Fix team name validation * Update i18n strings * Add autofocus * Pass translation-check * Fix goToRoomById call * Fix JSX expression * [FIX] Unexpected open or close visitor info (#21094) * fix unexpected open or close visitor info * fix lgtm bot warning Co-authored-by: Tasso Evangelista <[email protected]> Co-authored-by: Tasso Evangelista <[email protected]> Co-authored-by: Renato Becker <[email protected]> * Type check useMethod hook * Type check useEndpoint hook * Type check useTranslation hook * [NEW] use _rocketchatLogger in Apps debugLog (#21000) * Remove redundant polyfill * [IMPROVE] Improve Apps permission modal (#21193) * improve modal design * add en and pt-BR translations * fix icon size * [NEW][APPS] Map description as a room value in Apps (#20811) * map 'description' as a room value * Update Apps-Engine version * [FIX] Wrong license seats number administration info panel (#21222) * Use active users to display on limit of users for the license on info panel * Print more info about issues with licenses on server Co-authored-by: dougfabris <[email protected]> Co-authored-by: gabriellsh <[email protected]> Co-authored-by: Tiago Evangelista Pinto <[email protected]> Co-authored-by: Gabriel Henriques <[email protected]> Co-authored-by: Tasso Evangelista <[email protected]> Co-authored-by: Renato Becker <[email protected]> Co-authored-by: meomay503 <[email protected]> Co-authored-by: Lucas Sartor Chauvin <[email protected]> Co-authored-by: Rodrigo Nascimento <[email protected]>
- Loading branch information
1 parent
93be4fe
commit a3a540d
Showing
69 changed files
with
1,263 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
|
||
import GenericModal, { GenericModalDoNotAskAgain } from './GenericModal'; | ||
|
||
|
||
export default { | ||
title: 'components/GenericModal', | ||
component: GenericModal, | ||
}; | ||
|
||
const func = () => null; | ||
const defaultProps = { onClose: func, onConfirm: func, onCancel: func }; | ||
|
||
export const _default = () => <GenericModal {...defaultProps} />; | ||
export const Danger = () => <GenericModal {...defaultProps} variant='danger' />; | ||
export const Warning = () => <GenericModal {...defaultProps} variant='warning' />; | ||
export const Success = () => <GenericModal {...defaultProps} variant='success' />; | ||
export const WithDontAskAgain = () => <GenericModalDoNotAskAgain dontAskAgain={{ action: '', label: '' }} {...defaultProps} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Box, Button, ButtonGroup, Icon, Modal, ButtonProps } from '@rocket.chat/fuselage'; | ||
import React, { FC } from 'react'; | ||
|
||
import { useTranslation } from '../contexts/TranslationContext'; | ||
import { withDoNotAskAgain, RequiredModalProps } from './withDoNotAskAgain'; | ||
|
||
type VariantType = 'danger' | 'warning' | 'info' | 'success'; | ||
|
||
type GenericModalProps = RequiredModalProps & { | ||
variant?: VariantType; | ||
cancelText?: string; | ||
confirmText?: string; | ||
title?: string; | ||
icon?: string; | ||
onCancel?: () => void; | ||
onClose: () => void; | ||
onConfirm: () => void; | ||
}; | ||
|
||
const iconMap = { | ||
danger: 'modal-warning', | ||
warning: 'modal-warning', | ||
info: 'info', | ||
success: 'check', | ||
}; | ||
|
||
const getButtonProps = (variant: VariantType): ButtonProps => { | ||
switch (variant) { | ||
case 'danger': | ||
return { primary: true, danger: true }; | ||
case 'warning': | ||
return { primary: true }; | ||
default: | ||
return { }; | ||
} | ||
}; | ||
|
||
const GenericModal: FC<GenericModalProps> = ({ | ||
variant = 'info', | ||
children, | ||
cancelText, | ||
confirmText, | ||
title, | ||
icon, | ||
onCancel, | ||
onClose, | ||
onConfirm, | ||
dontAskAgain, | ||
...props | ||
}) => { | ||
const t = useTranslation(); | ||
|
||
return <Modal {...props}> | ||
<Modal.Header> | ||
{icon === null && <Icon color={variant} name={icon ?? iconMap[variant]} size={24}/>} | ||
<Modal.Title>{title ?? t('Are_you_sure')}</Modal.Title> | ||
<Modal.Close onClick={onClose}/> | ||
</Modal.Header> | ||
<Modal.Content fontScale='p1'> | ||
{children} | ||
</Modal.Content> | ||
<Modal.Footer> | ||
<Box display='flex' flexDirection='row' justifyContent='space-between' alignItems='center'> | ||
{dontAskAgain} | ||
<ButtonGroup align='end' flexGrow={1}> | ||
{onCancel && <Button ghost onClick={onCancel}>{cancelText ?? t('Cancel')}</Button>} | ||
<Button {...getButtonProps(variant)} onClick={onConfirm}>{confirmText ?? t('Ok')}</Button> | ||
</ButtonGroup> | ||
</Box> | ||
</Modal.Footer> | ||
</Modal>; | ||
}; | ||
|
||
// TODO update withDoNotAskAgain to use onConfirm istead of confirm | ||
export const GenericModalDoNotAskAgain = withDoNotAskAgain<GenericModalProps>(({ confirm, ...props }) => <GenericModal onConfirm={confirm} {...props}/>); | ||
|
||
export default GenericModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React, { FC, useState } from 'react'; | ||
import { Avatar, AvatarProps, Skeleton } from '@rocket.chat/fuselage'; | ||
|
||
export type BaseAvatarProps = AvatarProps; | ||
|
||
const BaseAvatar: FC<BaseAvatarProps> = ({ size, ...props }) => { | ||
const [error, setError] = useState<unknown>(false); | ||
|
||
if (error) { | ||
return <Skeleton variant='rect' {...props} />; | ||
} | ||
|
||
return <Avatar onError={setError} size={size} {...props}/>; | ||
}; | ||
|
||
export default BaseAvatar; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { FC, memo } from 'react'; | ||
|
||
import BaseAvatar, { BaseAvatarProps } from './BaseAvatar'; | ||
import { useUserAvatarPath } from '../../contexts/AvatarUrlContext'; | ||
|
||
type UserAvatarProps = Omit<BaseAvatarProps, 'url' | 'title'> & { | ||
username: string; | ||
etag?: string; | ||
url?: string; | ||
}; | ||
|
||
const UserAvatar: FC<UserAvatarProps> = ({ username, etag, ...rest }) => { | ||
const getUserAvatarPath = useUserAvatarPath(); | ||
const { | ||
url = getUserAvatarPath(username, etag), | ||
...props | ||
} = rest; | ||
|
||
return <BaseAvatar url={url} title={username} {...props}/>; | ||
}; | ||
|
||
export default memo(UserAvatar); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { createContext, useCallback, useContext, useMemo } from 'react'; | ||
|
||
import { ServerEndpointMethodOf, ServerEndpointPath, ServerEndpointFunction, ServerEndpointRequestPayload, ServerEndpointFormData, ServerEndpointResponsePayload } from './endpoints'; | ||
import { ServerMethodFunction, ServerMethodName, ServerMethodParameters, ServerMethodReturn, ServerMethods } from './methods'; | ||
|
||
type ServerContextValue = { | ||
info: {}; | ||
absoluteUrl: (path: string) => string; | ||
callMethod?: <MethodName extends ServerMethodName>(methodName: MethodName, ...args: ServerMethodParameters<MethodName>) => Promise<ServerMethodReturn<MethodName>>; | ||
callEndpoint?: < | ||
Method extends ServerEndpointMethodOf<Path>, | ||
Path extends ServerEndpointPath | ||
>(httpMethod: Method, endpoint: Path, params: ServerEndpointRequestPayload<Method, Path>, formData?: ServerEndpointFormData<Method, Path>) => Promise<ServerEndpointResponsePayload<Method, Path>>; | ||
uploadToEndpoint: (endpoint: string, params: any, formData: any) => Promise<void>; | ||
getStream: (streamName: string, options?: {}) => <T>(eventName: string, callback: (data: T) => void) => () => void; | ||
}; | ||
|
||
export const ServerContext = createContext<ServerContextValue>({ | ||
info: {}, | ||
absoluteUrl: (path) => path, | ||
uploadToEndpoint: async () => undefined, | ||
getStream: () => () => (): void => undefined, | ||
}); | ||
|
||
export const useServerInformation = (): {} => useContext(ServerContext).info; | ||
|
||
export const useAbsoluteUrl = (): ((path: string) => string) => useContext(ServerContext).absoluteUrl; | ||
|
||
export const useMethod = <MethodName extends keyof ServerMethods>( | ||
methodName: MethodName, | ||
): ServerMethodFunction<MethodName> => { | ||
const { callMethod } = useContext(ServerContext); | ||
|
||
return useCallback( | ||
(...args: ServerMethodParameters<MethodName>) => { | ||
if (!callMethod) { | ||
throw new Error(`cannot use useMethod(${ methodName }) hook without a wrapping ServerContext`); | ||
} | ||
|
||
return callMethod(methodName, ...args); | ||
}, | ||
[callMethod, methodName], | ||
); | ||
}; | ||
|
||
export const useEndpoint = < | ||
Method extends ServerEndpointMethodOf<Path>, | ||
Path extends ServerEndpointPath | ||
>(httpMethod: Method, endpoint: Path): ServerEndpointFunction<Method, Path> => { | ||
const { callEndpoint } = useContext(ServerContext); | ||
|
||
return useCallback((params: ServerEndpointRequestPayload<Method, Path>, formData?: ServerEndpointFormData<Method, Path>) => { | ||
if (!callEndpoint) { | ||
throw new Error(`cannot use useEndpoint(${ httpMethod }, ${ endpoint }) hook without a wrapping ServerContext`); | ||
} | ||
|
||
return callEndpoint(httpMethod, endpoint, params, formData); | ||
}, [callEndpoint, endpoint, httpMethod]); | ||
}; | ||
|
||
export const useUpload = (endpoint: string): (params: any, formData: any) => Promise<void> => { | ||
const { uploadToEndpoint } = useContext(ServerContext); | ||
return useCallback((params, formData: any) => uploadToEndpoint(endpoint, params, formData), [endpoint, uploadToEndpoint]); | ||
}; | ||
|
||
export const useStream = ( | ||
streamName: string, | ||
options?: {}, | ||
): <T>(eventName: string, callback: (data: T) => void) => (() => void) => { | ||
const { getStream } = useContext(ServerContext); | ||
return useMemo(() => getStream(streamName, options), [getStream, streamName, options]); | ||
}; |
Oops, something went wrong.