Skip to content

Commit

Permalink
feat: Auto-complete email domain and pre-fill name based on email or …
Browse files Browse the repository at this point in the history
…existing employee data (#2930)
  • Loading branch information
Innocent-Akim authored Aug 19, 2024
1 parent 7ffcd36 commit 7a9df76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 16 additions & 1 deletion apps/web/lib/features/team/invite/invite-form-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IInviteEmail } from '@app/interfaces';
import { AxiosError } from 'axios';
import { isEmail, isNotEmpty } from 'class-validator';
import { BackButton, Button, Card, InputField, Modal, Text } from 'lib/components';
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslations } from 'next-intl';
import { InviteEmailDropdown } from './invite-email-dropdown';

Expand All @@ -21,6 +21,8 @@ export function InviteFormModal({ open, closeModal }: { open: boolean; closeModa
const { workingEmployees } = useEmployee();
const [currentOrgEmails, setCurrentOrgEmails] = useState<IInviteEmail[]>([]);
const { activeTeam } = useOrganizationTeams();
const nameInputRef = useRef<HTMLInputElement>(null);


useEffect(() => {
if (activeTeam?.members) {
Expand All @@ -38,9 +40,21 @@ export function InviteFormModal({ open, closeModal }: { open: boolean; closeModa
}, [workingEmployees, workingEmployees.length, activeTeam]);

const handleAddNew = (email: string) => {

if (!email.includes('@')) {
email = `${email}@gmail.com`;
}

const newItem = { title: email, name: '' };
setSelectedEmail(newItem);

setCurrentOrgEmails([...currentOrgEmails, newItem]);
const extractedName = email.split('@')[0];
if (nameInputRef.current) {
nameInputRef.current.value = extractedName;
nameInputRef.current.focus();
nameInputRef.current.select();
}
};

const handleSubmit = useCallback(
Expand Down Expand Up @@ -99,6 +113,7 @@ export function InviteFormModal({ open, closeModal }: { open: boolean; closeModa
/>

<InputField
ref={nameInputRef}
type="text"
name="name"
placeholder={t('form.TEAM_MEMBER_NAME_PLACEHOLDER')}
Expand Down
8 changes: 3 additions & 5 deletions apps/web/lib/features/user-profile-plans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ type FilterOutstanding = 'ALL' | 'DATE';

export function UserProfilePlans() {
const t = useTranslations();
const defaultTab =
typeof window !== 'undefined'
? (window.localStorage.getItem('daily-plan-tab') as FilterTabs) || null
: 'Today Tasks';

const profile = useUserProfilePage();
const { todayPlan, futurePlans, pastPlans, outstandingPlans, sortedPlans, profileDailyPlans } = useDailyPlan();
const fullWidth = useRecoilValue(fullWidthState);
const [currentTab, setCurrentTab] = useState<FilterTabs>(defaultTab || 'Today Tasks');
const [currentOutstanding, setCurrentOutstanding] = useLocalStorageState<FilterOutstanding>('outstanding', 'ALL');

const [currentTab, setCurrentTab] = useLocalStorageState<FilterTabs>('daily-plan-tab', 'Today Tasks');


const [currentDataDailyPlan, setCurrentDataDailyPlan] = useRecoilState(dataDailyPlanState);
const { setDate, date } = useDateRange(currentTab);

Expand Down

0 comments on commit 7a9df76

Please sign in to comment.