Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
fix(meetings): bug fixes after test cases (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
enkhtuvshinD authored Oct 10, 2023
1 parent a75927b commit 368e75c
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 69 deletions.
3 changes: 1 addition & 2 deletions packages/plugin-meetings-api/src/models/Meetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export const loadMeetingClass = (model: IModels) => {
}
const result = await model.Meetings.findOne({
_id: doc._id,
createdBy: user._id,
status: { $ne: 'completed' }
createdBy: user._id
});
if (result) {
await model.Meetings.updateOne(
Expand Down
76 changes: 21 additions & 55 deletions packages/plugin-meetings-ui/src/components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Button from '@erxes/ui/src/components/Button';
import { __, router } from '@erxes/ui/src/utils';
import React, { useEffect, useState } from 'react';
import MeetingFormContainer from '../containers/myCalendar/meeting/Form';
import MyMeetingListContainer from '../containers/myMeetings/List';
import { Title } from '@erxes/ui-settings/src/styles';
import ModalTrigger from '@erxes/ui/src/components/ModalTrigger';
import Wrapper from '@erxes/ui/src/layout/components/Wrapper';
Expand All @@ -11,10 +10,9 @@ import DataWithLoader from '@erxes/ui/src/components/DataWithLoader';
import { menuMeeting } from '../contants';
import { MyCalendarList } from './myCalendar/MyCalendar';
import SideBar from '../containers/myCalendar/SideBar';
import SideBarContainer from '../containers/myMeetings/SideBar';
import { IUser } from '@erxes/ui/src/auth/types';
import { FormControl } from '@erxes/ui/src/components';
import { MeetingsQueryResponse } from '../types';
import MyMeetings from './myMeetings/MyMeetings';

type Props = {
meetings: any;
Expand All @@ -36,28 +34,17 @@ function List(props: Props) {
currentUser,
meetingQuery
} = props;
const { meetingId, searchValue } = queryParams;
const { meetingId } = queryParams;

const [component, setComponent] = useState(<div />);
const [leftSideBar, setLeftSideBar] = useState(<div />);

const [searchText, setSearchValue] = useState(searchValue);

const routePath = location.pathname.split('/').slice(-1)[0];

useEffect(() => {
switch (routePath) {
case 'myMeetings':
setComponent(
<MyMeetingListContainer history={history} queryParams={queryParams} />
);
setLeftSideBar(
<SideBarContainer
history={history}
queryParams={queryParams}
currentUser={currentUser}
/>
);
<MyMeetings {...props} />;
break;
default:
setComponent(
Expand Down Expand Up @@ -102,48 +89,27 @@ function List(props: Props) {
/>
);

const searchHandler = e => {
const searchValue = e.target.value;

setSearchValue(searchValue);

setTimeout(() => {
router.removeParams(history, 'page');
router.setParams(history, { searchValue });
}, 500);
};
const backToCalendar = () => {
router.removeParams(history, 'meetingId');
};
const actionBarRight =
routePath === 'myCalendar' ? (
meetingId ? (
<Button
btnStyle="success"
size="small"
icon="calendar-alt"
onClick={backToCalendar}
>
{__('Back to calendar')}
</Button>
) : (
<ModalTrigger
title={__('Create meetings')}
trigger={trigger}
content={modalContent}
enforceFocus={false}
size="xl"
/>
)
) : (
<FormControl
type="text"
placeholder={__('Type to search')}
defaultValue={searchText}
onChange={searchHandler}
autoFocus={true}
/>
);
const actionBarRight = meetingId ? (
<Button
btnStyle="success"
size="small"
icon="calendar-alt"
onClick={backToCalendar}
>
{__('Back to calendar')}
</Button>
) : (
<ModalTrigger
title={__('Create meetings')}
trigger={trigger}
content={modalContent}
enforceFocus={false}
size="xl"
/>
);

const title = !meetingId && (
<Title capitalize={true}>{__('My Calendar')}</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const SideBar = (props: Props) => {
</Box>
)}
{tommorowMeetings(filteredMeeting)?.length > 0 && (
<Box title="Tommorow" name={`tomorrow`} isOpen={true}>
<Box title="Tomorrow" name={`tomorrow`} isOpen={true}>
<SidebarList noTextColor noBackground id="SideBar">
{tommorowMeetings(filteredMeeting)?.map(meeting => {
return ListItem(meeting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import {
import { IMeeting, ITopic } from '../../../types';

import { TopicFormContainer } from '../../../containers/myCalendar/topic/Form';
import Form from '../../../containers/myCalendar/meeting/Form';

import Button from '@erxes/ui/src/components/Button';
import { Link } from 'react-router-dom';
import { DrawerDetail } from '@erxes/ui-automations/src/styles';
import queries from '../../../graphql/queries';
import { gql } from '@apollo/client';

type Props = {
meetingDetail: IMeeting;
Expand Down Expand Up @@ -88,6 +92,25 @@ export const MeetingDetail = (props: Props) => {
/>
);

const editTrigger = (
<Button id={'EditMeetingButton'} btnStyle="success" icon="edit-3">
Edit
</Button>
);

const editModalContent = props => (
<Form
{...props}
meeting={meetingDetail}
refetch={[
{
query: gql(queries.meetingDetail),
variables: { _id: meetingDetail._id }
}
]}
/>
);

const renderTabContent = () => {
return (
<>
Expand Down Expand Up @@ -195,6 +218,14 @@ export const MeetingDetail = (props: Props) => {
? 'Start meeting'
: 'End meeting'}
</Button>

<ModalTrigger
title={__('Edit meeting')}
trigger={editTrigger}
content={editModalContent}
enforceFocus={false}
size="xl"
/>
</MeetingDetailFooter>
)}
</MeetingWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Button from '@erxes/ui/src/components/Button';
import { ModalFooter } from '@erxes/ui/src/styles/main';
import ControlLabel from '@erxes/ui/src/components/form/Label';
import { IButtonMutateProps, IFormProps, IOption } from '@erxes/ui/src/types';
import { __ } from '@erxes/ui/src/utils';
import { __, Alert } from '@erxes/ui/src/utils';
import React, { useEffect, useState } from 'react';
import { ICommonFormProps } from '@erxes/ui-settings/src/common/types';
import { IMeeting } from '../../../types';
Expand Down Expand Up @@ -44,7 +44,7 @@ export const MeetingForm = (props: Props) => {
let dealInitialId = dealId ? [dealId] : '';

const [userIds, setUserIds] = useState([props.currentUser._id] || []);
const [companyId, setCompanyId] = useState('');
const [companyId, setCompanyId] = useState(meeting?.companyId || '');
const [title, setTitle] = useState('');
const [selectedMethod, setSelectedMethod] = useState('');
const [dealIds, setDealIds] = useState(dealInitialId);
Expand All @@ -53,7 +53,7 @@ export const MeetingForm = (props: Props) => {
calendarDate?.startDate || new Date()
);
const [endDate, setEndDate] = useState<string | Date>(
calendarDate?.endDate || new Date()
calendarDate?.endDate || ''
);

useEffect(() => {
Expand Down Expand Up @@ -112,7 +112,9 @@ export const MeetingForm = (props: Props) => {
};

const onEndDateChange = dateVal => {
setEndDate(dateVal);
if (new Date() < dateVal) {
setEndDate(dateVal);
} else Alert.warning('Please choose the correct date');
};

const renderDatePicker = () => {
Expand Down Expand Up @@ -160,7 +162,6 @@ export const MeetingForm = (props: Props) => {
const { closeModal, renderButton } = props;
const { values, isSubmitted } = formProps;
const object = meeting || ({} as IMeeting);

let dealOptions =
(deals &&
deals.map((deal: any) => ({
Expand All @@ -182,6 +183,7 @@ export const MeetingForm = (props: Props) => {
name="companyId"
onSelect={onCompanySelect}
multi={false}
initialValue={companyId}
/>
</FormGroup>

Expand Down Expand Up @@ -263,7 +265,7 @@ export const MeetingForm = (props: Props) => {
</Button>

{renderButton({
passedName: 'meetings',
passedName: 'meeting',
values: generateDoc(values),
isSubmitted,
callback: closeModal,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { __, router } from '@erxes/ui/src/utils';
import React, { useState } from 'react';

import Wrapper from '@erxes/ui/src/layout/components/Wrapper';
import DataWithLoader from '@erxes/ui/src/components/DataWithLoader';

import SideBarContainer from '../myMeetings/SideBar';
import { IUser } from '@erxes/ui/src/auth/types';
import { FormControl } from '@erxes/ui/src/components';
import { MeetingsQueryResponse } from '../../types';
import MyMeetingListContainer from '../../containers/myMeetings/List';
import { menuMeeting } from '../../contants';

type Props = {
meetings: any;
loading: boolean;
queryParams: any;
route?: string;
history: string;
refetchQueries?: any;
currentUser: IUser;
meetingQuery?: MeetingsQueryResponse;
};

function MyMeetings(props: Props) {
const { loading, queryParams, history, currentUser } = props;
const { searchValue } = queryParams;
const [searchText, setSearchValue] = useState(searchValue);

const searchHandler = e => {
const searchValue = e.target.value;

setSearchValue(searchValue);

setTimeout(() => {
router.removeParams(history, 'page');
router.setParams(history, { searchValue });
}, 500);
};

const leftSideBar = (
<SideBarContainer
history={history}
queryParams={queryParams}
currentUser={currentUser}
/>
);

const actionBarRight = (
<FormControl
type="text"
placeholder={__('Type to search')}
defaultValue={searchText}
onChange={searchHandler}
autoFocus={true}
/>
);

const actionBar = <Wrapper.ActionBar right={actionBarRight} wideSpacing />;
return (
<Wrapper
header={
<Wrapper.Header title={__('My Meetings')} submenu={menuMeeting()} />
}
actionBar={actionBar}
content={
<DataWithLoader
data={
<MyMeetingListContainer
history={history}
queryParams={queryParams}
/>
}
loading={loading}
count={1}
emptyText={__('Theres no meetings')}
emptyImage="/images/actions/8.svg"
/>
}
leftSidebar={leftSideBar}
transparent={true}
hasBorder
/>
);
}

export default MyMeetings;
6 changes: 4 additions & 2 deletions packages/plugin-meetings-ui/src/components/myMeetings/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const Row = (props: Props) => {
);
};

const content = props => <Form {...props} meeting={meeting} />;
const content = props => (
<Form {...props} meeting={meeting} refetch={['meetings']} />
);

const onTrClick = () => {
history.push(`/meetings/myCalendar?meetingId=${meeting._id}`);
Expand All @@ -58,7 +60,7 @@ export const Row = (props: Props) => {
<td onClick={onClick}>
<ActionButtons>
<ModalTrigger
title="Edit tag"
title="Edit meeting"
trigger={editTrigger}
content={content}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const MyMeetingListContainer = (props: FinalProps) => {
companyId,
searchValue
} = queryParams;

const { data, loading } = useQuery(gql(queries.meetings), {
variables: {
perPage: parseInt(perPage?.toString()) || 10,
Expand All @@ -44,8 +45,7 @@ const MyMeetingListContainer = (props: FinalProps) => {
userId: ownerId,
companyId,
searchValue
},
fetchPolicy: 'no-cache'
}
});

const { data: countData, loading: countLoading } = useQuery(
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-meetings-ui/src/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ query MeetingDetail($_id: String!) {
createdAt
status
companyId
participantIds
dealIds
deals{
_id
boardId
Expand Down
Loading

0 comments on commit 368e75c

Please sign in to comment.