Skip to content

Commit

Permalink
Merge pull request #2761 from ever-co/stage
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Jul 18, 2024
2 parents 9b880fa + dc04923 commit ace46a9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 40 deletions.
42 changes: 23 additions & 19 deletions apps/web/app/[locale]/auth/password/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AuthLayout } from 'lib/layout';
import { useTranslations } from 'next-intl';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { WorkSpaceComponent } from '../passcode/component';
import SocialLogins from '../social-logins-buttons';
import { LAST_WORSPACE_AND_TEAM, USER_SAW_OUTSTANDING_NOTIFICATION } from '@app/constants';
Expand Down Expand Up @@ -116,29 +116,35 @@ function WorkSpaceScreen({ form, className }: { form: TAuthenticationPassword }
[selectedWorkspace, selectedTeam, form]
);

const hasMultipleTeams = useMemo(
() => form.workspaces.some((workspace) => workspace.current_teams.length > 1),
[form.workspaces]
);

useEffect(() => {
if (form.workspaces.length === 1) {
setSelectedWorkspace(0);
if (form.workspaces.length === 1 && !hasMultipleTeams) {
setTimeout(() => {
document.getElementById('continue-to-workspace')?.click();
}, 100);
}

const currentTeams = form.workspaces[0]?.current_teams;
const currentTeams = form.workspaces.find((el) => el.current_teams && el.current_teams.length)?.current_teams;
const lastSelectedTeamId = window.localStorage.getItem(LAST_WORSPACE_AND_TEAM);

if (form.workspaces.length === 1 && currentTeams?.length === 1) {
if (currentTeams) {
setSelectedWorkspace(
form.workspaces.findIndex((el) =>
el.current_teams.find((el) => el.team_id == currentTeams[0]?.team_id)
) || 0
);
setSelectedTeam(currentTeams[0].team_id);
} else {
const lastSelectedTeam = window.localStorage.getItem(LAST_WORSPACE_AND_TEAM) || currentTeams[0].team_id;
const lastSelectedWorkspace =
form.workspaces.findIndex((workspace) =>
workspace.current_teams.find((team) => team.team_id === lastSelectedTeam)
) || 0;
setSelectedTeam(lastSelectedTeam);
setSelectedWorkspace(lastSelectedWorkspace);
}

if (form.workspaces.length === 1 && (currentTeams?.length || 0) <= 1) {
setTimeout(() => {
document.getElementById('continue-to-workspace')?.click();
}, 100);
if (lastSelectedTeamId && lastSelectedTeamId !== 'undefined') {
setSelectedWorkspace(
form.workspaces.findIndex((el) => el.current_teams.find((el) => el.team_id == lastSelectedTeamId)) || 0
);
setSelectedTeam(lastSelectedTeamId);
}
}, [form.workspaces]);

Expand All @@ -151,8 +157,6 @@ function WorkSpaceScreen({ form, className }: { form: TAuthenticationPassword }
}
}, [form.authScreen, router]);

const hasMultipleTeams = form.workspaces.some((workspace) => workspace.current_teams.length > 1);

return (
<>
{/* The workspace component will be visible only if there are two or many workspaces and/or teams */}
Expand Down
12 changes: 7 additions & 5 deletions apps/web/app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@app/services/server/requests';
import { setAuthCookies } from '@app/helpers/cookies';
import { recaptchaVerification } from '@app/services/server/recaptcha';
import { RECAPTCHA_SECRET_KEY, VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants';
import { RECAPTCHA_SECRET_KEY, SMTP_PASSWORD, SMTP_USERNAME, VERIFY_EMAIL_CALLBACK_PATH } from '@app/constants';
import { NextResponse } from 'next/server';

export async function POST(req: Request) {
Expand Down Expand Up @@ -84,10 +84,12 @@ export async function POST(req: Request) {
const { data: tenant } = await createTenantRequest(body.team, auth_token);

// Create tenant SMTP
await createTenantSmtpRequest({
access_token: auth_token,
tenantId: tenant.id
});
if (SMTP_USERNAME && SMTP_PASSWORD) {
await createTenantSmtpRequest({
access_token: auth_token,
tenantId: tenant.id
});
}

// Create user organization
const { data: organization } = await createOrganizationRequest(
Expand Down
25 changes: 14 additions & 11 deletions apps/web/app/hooks/features/useDailyPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function useDailyPlan() {
const { loading: addTaskToPlanLoading, queryCall: addTaskToPlanQueryCall } = useQuery(addTaskToPlanAPI);
const { loading: removeTaskFromPlanLoading, queryCall: removeTAskFromPlanQueryCall } =
useQuery(removeTaskFromPlanAPI);
const { loading: removeManyTaskFromPlanLoading, queryCall: removeManyTaskPlanQueryCall } = useQuery(removeManyTaskFromPlansAPI);
const { loading: removeManyTaskFromPlanLoading, queryCall: removeManyTaskPlanQueryCall } =
useQuery(removeManyTaskFromPlansAPI);

const { loading: deleteDailyPlanLoading, queryCall: deleteDailyPlanQueryCall } = useQuery(deleteDailyPlanAPI);

Expand Down Expand Up @@ -164,7 +165,6 @@ export function useDailyPlan() {
]
);


const removeTaskFromPlan = useCallback(
async (data: IDailyPlanTasksUpdate, planId: string) => {
const res = await removeTAskFromPlanQueryCall(data, planId);
Expand Down Expand Up @@ -209,7 +209,6 @@ export function useDailyPlan() {
setEmployeePlans(updatedEmployeePlans);
getMyDailyPlans();
return res;

},
[
removeManyTaskPlanQueryCall,
Expand All @@ -219,7 +218,7 @@ export function useDailyPlan() {
setEmployeePlans,
setProfileDailyPlans
]
)
);

const deleteDailyPlan = useCallback(
async (planId: string) => {
Expand Down Expand Up @@ -305,13 +304,17 @@ export function useDailyPlan() {
if (activeTeam && currentUser) {
const lastAlertDate = localStorage.getItem(TODAY_PLAN_ALERT_SHOWN_DATE);
const today = new Date().toISOString().split('T')[0];
const totalMemberWorked = currentUser?.totalTodayTasks.reduce(
(previousValue, currentValue) => previousValue + currentValue.duration,
0
);
const showTodayPlanTrigger = todayPlan && todayPlan.length > 0 && totalMemberWorked > 0;
if (lastAlertDate === today) {
setAddTodayPlanTrigger({ canBeSeen: !!showTodayPlanTrigger, alreadySeen: true });

if (currentUser?.totalTodayTasks) {
const totalMemberWorked = currentUser?.totalTodayTasks.reduce(
(previousValue, currentValue) => previousValue + currentValue.duration,
0
);

const showTodayPlanTrigger = todayPlan && todayPlan.length > 0 && totalMemberWorked > 0;
if (lastAlertDate === today) {
setAddTodayPlanTrigger({ canBeSeen: !!showTodayPlanTrigger, alreadySeen: true });
}
}
}
};
Expand Down
8 changes: 3 additions & 5 deletions apps/web/lib/components/inputs/auth-code-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const AuthCodeInputField = forwardRef<AuthCodeRef, AuthCodeProps>(
defaultValue,
hintType,
autoComplete = '',
submitCode,
submitCode
},
ref
) => {
Expand Down Expand Up @@ -129,13 +129,12 @@ export const AuthCodeInputField = forwardRef<AuthCodeRef, AuthCodeProps>(
if (autoComplete && autoComplete.length > 0) {
handleAutoComplete(autoComplete);
setCanSubmit(true);

}
}, [autoComplete, canSubmit]);

useEffect(() => {
submitCode && submitCode();
}, [canSubmit])
canSubmit && submitCode && submitCode();
}, []);

const sendResult = () => {
const res = inputsRef.current.map((input) => input.value).join('');
Expand Down Expand Up @@ -212,7 +211,6 @@ export const AuthCodeInputField = forwardRef<AuthCodeRef, AuthCodeProps>(
};

const handleAutoComplete = (code: string) => {

let currentInput = 0;

for (let i = 0; i < code.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions apps/web/lib/settings/danger-zone-team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTranslations } from 'next-intl';
import { useRecoilValue } from 'recoil';
import { RemoveModal } from './remove-modal';
import { TransferTeamModal } from './transfer-team-modal';
import { LAST_WORSPACE_AND_TEAM } from '@app/constants';

export const DangerZoneTeam = () => {
const t = useTranslations();
Expand All @@ -21,6 +22,7 @@ export const DangerZoneTeam = () => {

const handleDisposeTeam = useCallback(() => {
if (activeTeam) {
window.localStorage.removeItem(LAST_WORSPACE_AND_TEAM);
return deleteOrganizationTeam(activeTeam.id);
}
}, [activeTeam, deleteOrganizationTeam]);
Expand Down

0 comments on commit ace46a9

Please sign in to comment.