Skip to content

Commit

Permalink
fix: popup should not appear when the user clicks 'Back' (or the prof…
Browse files Browse the repository at this point in the history
…ile page) button (#2858)

Co-authored-by: Ruslan Konviser <[email protected]>
  • Loading branch information
CREDO23 and evereq authored Aug 19, 2024
1 parent c53baa7 commit a788c9c
Showing 1 changed file with 3 additions and 44 deletions.
47 changes: 3 additions & 44 deletions apps/web/lib/features/team-members-card-view.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import {
useAuthenticateUser,
useDailyPlan,
useModal,
useOrganizationEmployeeTeams,
useTeamInvitations,
useUserProfilePage
} from '@app/hooks';
import { useAuthenticateUser, useModal, useOrganizationEmployeeTeams, useTeamInvitations } from '@app/hooks';
import { Transition } from '@headlessui/react';
import { InviteFormModal } from './team/invite/invite-form-modal';
import { InvitedCard, InviteUserTeamCard } from './team/invite/user-invite-card';
import { InviteUserTeamSkeleton, UserTeamCard, UserTeamCardSkeleton } from '.';
import { OT_Member } from '@app/interfaces';
import React, { useCallback, useEffect, useState } from 'react';
import { DailyPlanCompareEstimatedModal } from './daily-plan';
import { DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE } from '@app/constants';
import React, { useCallback, useEffect } from 'react';

interface Props {
teamMembers: OT_Member[];
Expand All @@ -30,14 +21,6 @@ const TeamMembersCardView: React.FC<Props> = ({
}) => {
const { isTeamManager } = useAuthenticateUser();
const { teamInvitations } = useTeamInvitations();
const [isOpen, setIsOpen] = useState(false);
const { todayPlan } = useDailyPlan();
const profile = useUserProfilePage();
const defaultOpenPopup =
typeof window !== 'undefined'
? window.localStorage.getItem(DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE) || null
: new Date().toISOString().split('T')[0];
const plan = todayPlan.find((plan) => plan.date?.toString()?.startsWith(new Date()?.toISOString().split('T')[0]));

const { updateOrganizationTeamEmployeeOrderOnList } = useOrganizationEmployeeTeams();

Expand All @@ -48,16 +31,6 @@ const TeamMembersCardView: React.FC<Props> = ({

useEffect(() => setMemberOrdereds(members), [members]);

useEffect(() => {
if (plan) {
const currentDateString = new Date().toISOString().split('T')[0];
window.localStorage.setItem(DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE, currentDateString);
if (defaultOpenPopup !== currentDateString || !defaultOpenPopup) {
setIsOpen(true);
}
}
}, [defaultOpenPopup, plan]);

const handleChangeOrder = useCallback(
(employee: OT_Member, order: number) => {
updateOrganizationTeamEmployeeOrderOnList(employee, order);
Expand All @@ -78,22 +51,8 @@ const TeamMembersCardView: React.FC<Props> = ({

return (
<>
<DailyPlanCompareEstimatedModal
open={isOpen}
closeModal={() =>
setIsOpen((prev) => {
window.localStorage.setItem(
DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE,
new Date().toISOString().split('T')[0]
);
return !prev;
})
}
todayPlan={todayPlan}
profile={profile}
/>

<ul className="mt-7" ref={profile.loadTaskStatsIObserverRef}>

{/* Current authenticated user members */}
<Transition
show={!!currentUser}
Expand Down

0 comments on commit a788c9c

Please sign in to comment.