Skip to content

Commit

Permalink
feat(services): webmail added (#481)
Browse files Browse the repository at this point in the history
* feat(webmail): add the webmail button and the hooks for the authentication,Ref #473

* fix(webmail): webmail improvements

---------

Co-authored-by: FabrizioCostaMedich <fabrizio.costamedich@gmail.com>
Co-authored-by: Emanuele Coricciati <ema@MacBook-Air-di-Emanuele.local>
  • Loading branch information
3 people authored May 9, 2024
1 parent a02334d commit 5e5152a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@miblanchard/react-native-slider": "^2.2.0",
"@openspacelabs/react-native-zoomable-view": "^2.1.5",
"@orama/orama": "^2.0.0-beta.8",
"@polito/api-client": "^1.0.0-ALPHA.60",
"@polito/api-client": "^1.0.0-ALPHA.62",
"@react-native-async-storage/async-storage": "^1.17.11",
"@react-native-clipboard/clipboard": "^1.12.1",
"@react-native-community/blur": "^4.3.0",
Expand Down
30 changes: 30 additions & 0 deletions src/core/queries/webMailHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { WebmailApi } from '@polito/api-client';
import { useQuery } from '@tanstack/react-query';

import { pluckData } from '../../utils/queries';

export const WEBMAIL_LINK_QUERY_KEY = ['webmailLink'];

const UNREAD_MAIL_QUERY_KEY = ['unreadEmails'];

const useWebmailClient = (): WebmailApi => {
return new WebmailApi();
};

export const GetWebmailLink = async () => {
const webmailClient = useWebmailClient();

return webmailClient.getWebmailLink().then(pluckData);
};

export const useGetUnreadEmails = () => {
const webmailClient = useWebmailClient();

return useQuery(
UNREAD_MAIL_QUERY_KEY,
() => webmailClient.getUnreadEmailslNumber().then(pluckData),
{
refetchInterval: 5 * 60 * 1000, // 5 minutes
},
);
};
27 changes: 27 additions & 0 deletions src/features/services/screens/ServicesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
faBriefcase,
faClipboardQuestion,
faComments,
faEnvelope,
faIdCard,
faMobileScreenButton,
faNewspaper,
Expand All @@ -26,6 +27,11 @@ import { useNotifications } from '../../../core/hooks/useNotifications';
import { useOfflineDisabled } from '../../../core/hooks/useOfflineDisabled';
import { BOOKINGS_QUERY_KEY } from '../../../core/queries/bookingHooks';
import { TICKETS_QUERY_KEY } from '../../../core/queries/ticketHooks';
import {
GetWebmailLink,
WEBMAIL_LINK_QUERY_KEY,
useGetUnreadEmails,
} from '../../../core/queries/webMailHooks';
import { split } from '../../../utils/reducers';
import { ServiceCard } from '../components/ServiceCard';

Expand All @@ -42,6 +48,8 @@ export const ServicesScreen = () => {
const queryClient = useQueryClient();
const { peopleSearched } = usePreferencesContext();
const unreadTickets = getUnreadsCount(['services', 'tickets']);
const unreadEmailsQuery = useGetUnreadEmails();

const services = useMemo(() => {
return [
{
Expand Down Expand Up @@ -129,15 +137,34 @@ export const ServicesScreen = () => {
disabled: isOffline,
linkTo: { screen: 'Surveys' },
},
{
id: 'mail',
name: 'WebMail',
icon: faEnvelope,
disabled: isOffline,
unReadCount: unreadEmailsQuery.data
? parseInt(unreadEmailsQuery.data.unreadEmails, 10)
: 0,
onPress: () => {
queryClient
.fetchQuery(WEBMAIL_LINK_QUERY_KEY, GetWebmailLink, {
staleTime: 55 * 1000, // 55 seconds
cacheTime: 55 * 1000, // 55 seconds
})
.then(res => Linking.openURL(res.url ?? ''));
},
},
];
}, [
emailGuideRead,
getUnreadsCount,
isOffline,
peopleSearched?.length,
queryClient,
styles.badge,
t,
unreadTickets,
unreadEmailsQuery.data,
]);

const [favoriteServices, otherServices] = useMemo(
Expand Down

0 comments on commit 5e5152a

Please sign in to comment.