From 952da8146c98bfbf2179ea1b02080157a9e4aeb6 Mon Sep 17 00:00:00 2001 From: dougfabris Date: Mon, 26 Dec 2022 15:42:16 -0300 Subject: [PATCH] chore: add custom emoji empty state --- .../views/admin/customEmoji/CustomEmoji.tsx | 139 ++++++++++-------- 1 file changed, 81 insertions(+), 58 deletions(-) diff --git a/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx b/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx index 2eefba862450..9d7d077c80ce 100644 --- a/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx +++ b/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx @@ -1,6 +1,7 @@ -import { Box, Pagination } from '@rocket.chat/fuselage'; +import { Box, Pagination, States, StatesActions, StatesAction, StatesIcon, StatesTitle } from '@rocket.chat/fuselage'; import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; -import { useTranslation } from '@rocket.chat/ui-contexts'; +import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; +import { useQuery } from '@tanstack/react-query'; import type { FC, MutableRefObject } from 'react'; import React, { useEffect, useMemo, useState } from 'react'; @@ -16,22 +17,18 @@ import { } from '../../../components/GenericTable'; import { usePagination } from '../../../components/GenericTable/hooks/usePagination'; import { useSort } from '../../../components/GenericTable/hooks/useSort'; -import { useEndpointData } from '../../../hooks/useEndpointData'; -import { AsyncStatePhase } from '../../../lib/asyncState'; type CustomEmojiProps = { reload: MutableRefObject<() => void>; onClick: (emoji: string) => () => void; }; -const CustomEmoji: FC = function CustomEmoji({ onClick, reload }) { +const CustomEmoji: FC = ({ onClick, reload }) => { const t = useTranslation(); - const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination(); - const [text, setText] = useState(''); - const { sortBy, sortDirection, setSort } = useSort<'name'>('name'); + const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination(); const query = useDebouncedValue( useMemo( @@ -46,61 +43,87 @@ const CustomEmoji: FC = function CustomEmoji({ onClick, reload 500, ); - const { value: data, phase, reload: reloadEndPoint } = useEndpointData('/v1/emoji-custom.all', query); + const headers = useMemo( + () => [ + + {t('Name')} + , + + {t('Aliases')} + , + ], + [setSort, sortDirection, sortBy, t], + ); + + const getEmojiList = useEndpoint('GET', '/v1/emoji-custom.all'); + const { data, refetch, isSuccess, isLoading, isError } = useQuery(['getEmojiList', query], () => getEmojiList(query)); useEffect(() => { - reload.current = reloadEndPoint; - }, [reload, reloadEndPoint]); + reload.current = refetch; + }, [reload, refetch]); + return ( <> setText(text)} /> - - - - {t('Name')} - - - {t('Aliases')} - - - - {phase === AsyncStatePhase.LOADING && } - {phase === AsyncStatePhase.RESOLVED && - data && - data.emojis && - data.emojis.length > 0 && - data?.emojis.map((emojis) => ( - - - {emojis.name} - - - {emojis.aliases} - - - ))} - {/* {phase === AsyncStatePhase.RESOLVED && - !data.emojis.length - ))} */} - - - {phase === AsyncStatePhase.RESOLVED && ( - + {isLoading && ( + + {headers} + + + + + )} + {isSuccess && data && data.emojis.length > 0 && ( + <> + + {headers} + + {isSuccess && + data?.emojis.map((emojis) => ( + + + {emojis.name} + + + {emojis.aliases} + + + ))} + + + + + )} + {isSuccess && data && data.emojis.length === 0 && ( + + + {t('No_results_found')} + + )} + {isError && ( + + + {t('Something_went_wrong')} + + refetch()}>{t('Reload_page')} + + )} );