diff --git a/apps/web/app/hooks/features/useEmployee.ts b/apps/web/app/hooks/features/useEmployee.ts index 916877137..4ca1d9037 100644 --- a/apps/web/app/hooks/features/useEmployee.ts +++ b/apps/web/app/hooks/features/useEmployee.ts @@ -6,11 +6,13 @@ import { useRecoilState } from 'recoil'; import { useQuery } from '../useQuery'; import { useAuthenticateUser } from './useAuthenticateUser'; import { IUpdateEmployee } from '@app/interfaces'; +import { useFirstLoad } from '../useFirstLoad'; export const useEmployee = () => { const { user } = useAuthenticateUser(); const [workingEmployees, setWorkingEmployees] = useRecoilState(workingEmployeesState); const [workingEmployeesEmail, setWorkingEmployeesEmail] = useRecoilState(workingEmployeesEmailState); + const { firstLoad, firstLoadData: firstLoadDataEmployee } = useFirstLoad(); const { queryCall: getWorkingEmployeeQueryCall, loading: getWorkingEmployeeLoading } = useQuery(getWorkingEmployeesAPI); @@ -30,10 +32,13 @@ export const useEmployee = () => { }, [getWorkingEmployeeQueryCall, setWorkingEmployees, setWorkingEmployeesEmail, user]); useEffect(() => { - getWorkingEmployee(); - }, [getWorkingEmployee]); + if (firstLoad) { + getWorkingEmployee(); + } + }, [getWorkingEmployee, firstLoad]); return { + firstLoadDataEmployee, getWorkingEmployeeQueryCall, getWorkingEmployeeLoading, workingEmployees, @@ -41,12 +46,10 @@ export const useEmployee = () => { }; }; - export const useEmployeeUpdate = () => { const { queryCall: employeeUpdateQuery, loading: isLoading } = useQuery(updateEmployeeAPI); - const updateEmployee = useCallback(({ id, data - }: { id: string, data: IUpdateEmployee }) => { + const updateEmployee = useCallback(({ id, data }: { id: string; data: IUpdateEmployee }) => { employeeUpdateQuery({ id, data }) .then((res) => res.data) .catch((error) => { @@ -54,5 +57,5 @@ export const useEmployeeUpdate = () => { }); }, []); - return { updateEmployee, isLoading } -} + return { updateEmployee, isLoading }; +}; diff --git a/apps/web/app/hooks/features/useTeamInvitations.ts b/apps/web/app/hooks/features/useTeamInvitations.ts index 47a3bda8c..5c7b16585 100644 --- a/apps/web/app/hooks/features/useTeamInvitations.ts +++ b/apps/web/app/hooks/features/useTeamInvitations.ts @@ -107,7 +107,7 @@ export function useTeamInvitations() { const resendTeamInvitation = useCallback( (invitationId: string) => { - resendInviteQueryCall(invitationId); + return resendInviteQueryCall(invitationId); }, [resendInviteQueryCall] ); diff --git a/apps/web/app/hooks/features/useTimer.ts b/apps/web/app/hooks/features/useTimer.ts index 0712b14e9..d94e77b27 100644 --- a/apps/web/app/hooks/features/useTimer.ts +++ b/apps/web/app/hooks/features/useTimer.ts @@ -301,6 +301,16 @@ export function useTimer() { return; }); + promise.catch(() => { + if (taskId.current) { + updateLocalTimerStatus({ + lastTaskId: taskId.current, + runnedDateTime: 0, + running: false + }); + } + }); + /** * Updating the task status to "In Progress" when the timer is started. */ diff --git a/apps/web/components/shared/invite/invite-modal.tsx b/apps/web/components/shared/invite/invite-modal.tsx index 09b601351..21dc0c7b6 100644 --- a/apps/web/components/shared/invite/invite-modal.tsx +++ b/apps/web/components/shared/invite/invite-modal.tsx @@ -7,6 +7,7 @@ import React, { useState } from 'react'; import { IInvite, IInviteProps } from '../../../app/interfaces/hooks'; import { UserOutlineIcon } from 'assets/svg'; import { useTranslations } from 'next-intl'; +import { useToast } from '@components/ui/use-toast'; const initalValues: IInvite = { email: '', @@ -14,9 +15,15 @@ const initalValues: IInvite = { }; const InviteModal = ({ isOpen, Fragment, closeModal }: IInviteProps) => { const [formData, setFormData] = useState(initalValues); - const { inviteUser, inviteLoading } = useTeamInvitations(); + const { inviteUser, inviteLoading, teamInvitations, resendTeamInvitation, resendInviteLoading } = + useTeamInvitations(); + const [errors, setErrors] = useState({}); const t = useTranslations(); + const { toast } = useToast(); + + const isLoading = inviteLoading || resendInviteLoading; + const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setErrors((er) => { @@ -30,14 +37,44 @@ const InviteModal = ({ isOpen, Fragment, closeModal }: IInviteProps) => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); + const existingInvitation = teamInvitations.find((invitation) => invitation.email === formData.email); + + if (existingInvitation) { + resendTeamInvitation(existingInvitation.id).then(() => { + closeModal(); + + toast({ + variant: 'default', + title: t('common.INVITATION_SENT'), + description: t('common.INVITATION_SENT_TO_USER', { email: formData.email }), + duration: 5 * 1000 + }); + }); + return; + } + inviteUser(formData.email, formData.name) - .then(() => { + .then((data) => { setFormData(initalValues); closeModal(); + toast({ + variant: 'default', + title: t('common.INVITATION_SENT'), + description: t('common.INVITATION_SENT_TO_USER', { email: formData.email }), + duration: 5 * 1000 + }); }) .catch((err: AxiosError) => { if (err.response?.status === 400) { - setErrors((err.response?.data as any)?.errors || {}); + const data = err.response?.data as any; + + if ('errors' in data) { + setErrors(data.errors || {}); + } + + if ('message' in data && Array.isArray(data.message)) { + setErrors({ email: data.message[0] }); + } } }); }; @@ -109,10 +146,10 @@ const InviteModal = ({ isOpen, Fragment, closeModal }: IInviteProps) => { diff --git a/apps/web/locales/ar.json b/apps/web/locales/ar.json index 93bb77af4..cd91c9370 100644 --- a/apps/web/locales/ar.json +++ b/apps/web/locales/ar.json @@ -200,7 +200,9 @@ "PAUSED": "متوقف", "ONLINE": "متصل", "SKIP_ADD_LATER": "أضف لاحقًا", - "DAILYPLAN": "مخطط" + "DAILYPLAN": "مخطط", + "INVITATION_SENT": "تم إرسال دعوة بنجاح", + "INVITATION_SENT_TO_USER": "تم إرسال دعوة فريق إلى {email}." }, "hotkeys": { "HELP": "مساعدة", diff --git a/apps/web/locales/bg.json b/apps/web/locales/bg.json index 74a06840b..c2b557261 100644 --- a/apps/web/locales/bg.json +++ b/apps/web/locales/bg.json @@ -200,7 +200,9 @@ "PAUSED": "Пауза", "ONLINE": "Онлайн", "SKIP_ADD_LATER": "Добави по-късно", - "DAILYPLAN": "Планирано" + "DAILYPLAN": "Планирано", + "INVITATION_SENT": "Покана е изпратена успешно", + "INVITATION_SENT_TO_USER": "Покана е изпратена на {email}." }, "hotkeys": { "HELP": "Помощ", diff --git a/apps/web/locales/de.json b/apps/web/locales/de.json index 5f61f2dfa..d4f4703d2 100644 --- a/apps/web/locales/de.json +++ b/apps/web/locales/de.json @@ -200,7 +200,9 @@ "PAUSED": "Pausiert", "ONLINE": "Online", "SKIP_ADD_LATER": "Später hinzufügen", - "DAILYPLAN": "Plan dzienny" + "DAILYPLAN": "Plan dzienny", + "INVITATION_SENT": "Einladung erfolgreich gesendet", + "INVITATION_SENT_TO_USER": "Eine Teameinladung wurde an {email} gesendet." }, "hotkeys": { "HELP": "Hilfe", diff --git a/apps/web/locales/en.json b/apps/web/locales/en.json index c8456003b..2404933a2 100644 --- a/apps/web/locales/en.json +++ b/apps/web/locales/en.json @@ -200,7 +200,9 @@ "PAUSED": "Paused", "ONLINE": "Online", "SKIP_ADD_LATER": "Add later", - "DAILYPLAN": "Planned" + "DAILYPLAN": "Planned", + "INVITATION_SENT": "Invitation Sent Successfully", + "INVITATION_SENT_TO_USER": "A team invitation has been sent to {email}." }, "hotkeys": { "HELP": "Help", diff --git a/apps/web/locales/es.json b/apps/web/locales/es.json index 30018f78b..8a1aaa7bc 100644 --- a/apps/web/locales/es.json +++ b/apps/web/locales/es.json @@ -200,7 +200,9 @@ "PAUSED": "Pausado", "ONLINE": "En línea", "SKIP_ADD_LATER": "Agregar más tarde", - "DAILYPLAN": "Planificado" + "DAILYPLAN": "Planificado", + "INVITATION_SENT": "Invitación enviada con éxito", + "INVITATION_SENT_TO_USER": "Se ha enviado una invitación de equipo a {email}." }, "hotkeys": { "HELP": "Ayuda", diff --git a/apps/web/locales/fr.json b/apps/web/locales/fr.json index 1ba75589d..355ccf4da 100644 --- a/apps/web/locales/fr.json +++ b/apps/web/locales/fr.json @@ -200,7 +200,9 @@ "PAUSED": "En pause", "ONLINE": "En ligne", "SKIP_ADD_LATER": "Ajouter plus tard", - "DAILYPLAN": "Planifié" + "DAILYPLAN": "Planifié", + "INVITATION_SENT": "Invitation envoyée avec succès", + "INVITATION_SENT_TO_USER": "Une invitation a été envoyée à {email}." }, "hotkeys": { "HELP": "Aide", diff --git a/apps/web/locales/he.json b/apps/web/locales/he.json index 8ac756f77..67d706cd6 100644 --- a/apps/web/locales/he.json +++ b/apps/web/locales/he.json @@ -200,7 +200,9 @@ "PAUSED": "מושהה", "ONLINE": "מחובר", "SKIP_ADD_LATER": "הוסף מאוחר יותר", - "DAILYPLAN": "מְתוּכנָן" + "DAILYPLAN": "מְתוּכנָן", + "INVITATION_SENT": "ההזמנה נשלחה בהצלחה", + "INVITATION_SENT_TO_USER": "ההזמנה נשלחה ל{email}." }, "hotkeys": { "HELP": "עזרה", diff --git a/apps/web/locales/it.json b/apps/web/locales/it.json index d2ccf8528..6e51df61f 100644 --- a/apps/web/locales/it.json +++ b/apps/web/locales/it.json @@ -200,7 +200,9 @@ "PAUSED": "In Pausa", "ONLINE": "Online", "SKIP_ADD_LATER": "Aggiungi dopo", - "DAILYPLAN": "Pianificato" + "DAILYPLAN": "Pianificato", + "INVITATION_SENT": "Invito inviato con successo", + "INVITATION_SENT_TO_USER": "Un invito alla squadra è stato inviato a {email}." }, "hotkeys": { "HELP": "Aiuto", diff --git a/apps/web/locales/nl.json b/apps/web/locales/nl.json index 650534aff..906620c98 100644 --- a/apps/web/locales/nl.json +++ b/apps/web/locales/nl.json @@ -200,7 +200,9 @@ "PAUSED": "Gepauzeerd", "ONLINE": "Online", "SKIP_ADD_LATER": "Later toevoegen", - "DAILYPLAN": "Gepland" + "DAILYPLAN": "Gepland", + "INVITATION_SENT": "Uitnodiging verzonden", + "INVITATION_SENT_TO_USER": "Een teamuitnodiging is verzonden naar {email}." }, "hotkeys": { "HELP": "Help", diff --git a/apps/web/locales/pl.json b/apps/web/locales/pl.json index 0b43c4ea2..e53b3b7c0 100644 --- a/apps/web/locales/pl.json +++ b/apps/web/locales/pl.json @@ -200,7 +200,9 @@ "PAUSED": "Wstrzymany", "ONLINE": "Online", "SKIP_ADD_LATER": "Dodaj później", - "DAILYPLAN": "Planowane" + "DAILYPLAN": "Planowane", + "INVITATION_SENT": "Zaproszenie wysłane", + "INVITATION_SENT_TO_USER": "Zaproszenie zespołu zostało wysłane do {email}." }, "hotkeys": { "HELP": "Pomoc", diff --git a/apps/web/locales/pt.json b/apps/web/locales/pt.json index 7a5d3b546..f8f97c59e 100644 --- a/apps/web/locales/pt.json +++ b/apps/web/locales/pt.json @@ -200,7 +200,9 @@ "PAUSED": "Pausado", "ONLINE": "Online", "SKIP_ADD_LATER": "Adicionar depois", - "DAILYPLAN": "Planeado" + "DAILYPLAN": "Planeado", + "INVITATION_SENT": "Convite enviado com sucesso", + "INVITATION_SENT_TO_USER": "Um convite de equipe foi enviado para {email}." }, "hotkeys": { "HELP": "Ajuda", diff --git a/apps/web/locales/ru.json b/apps/web/locales/ru.json index 54e72c0dd..23351cc4c 100644 --- a/apps/web/locales/ru.json +++ b/apps/web/locales/ru.json @@ -200,7 +200,9 @@ "PAUSED": "Приостановлено", "ONLINE": "Онлайн", "SKIP_ADD_LATER": "Добавить позже", - "DAILYPLAN": "Планируется" + "DAILYPLAN": "Планируется", + "INVITATION_SENT": "Приглашение отправлено успешно", + "INVITATION_SENT_TO_USER": "Приглашение к команде было отправлено на {email}." }, "hotkeys": { "HELP": "Помощь", diff --git a/apps/web/locales/zh.json b/apps/web/locales/zh.json index 503938ab5..41eaf0ad4 100644 --- a/apps/web/locales/zh.json +++ b/apps/web/locales/zh.json @@ -200,7 +200,9 @@ "PAUSED": "暂停", "ONLINE": "在线", "SKIP_ADD_LATER": "稍后添加", - "DAILYPLAN": "計劃中" + "DAILYPLAN": "計劃中", + "INVITATION_SENT": "邀请已发送", + "INVITATION_SENT_TO_USER": "团队邀请已发送给 {email}。" }, "hotkeys": { "HELP": "帮助",