-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(meetings): add pinned user in meeting (#340)
- Loading branch information
1 parent
b2ac96f
commit d26cf02
Showing
26 changed files
with
420 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
packages/plugin-meetings-api/src/graphql/resolvers/customResolvers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import Meeting from './meeting'; | ||
import PinnedUsers from './pinnedUsers'; | ||
export default { | ||
Meeting | ||
Meeting, | ||
PinnedUsers | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/plugin-meetings-api/src/graphql/resolvers/customResolvers/pinnedUsers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default { | ||
async pinnedUsersInfo(pinnedUser) { | ||
if (!pinnedUser.pinnedUserIds) return null; | ||
return pinnedUser.pinnedUserIds.map(userId => { | ||
return { | ||
__typename: 'User', | ||
_id: userId | ||
}; | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/plugin-meetings-api/src/graphql/resolvers/mutations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Meeting from './meeting'; | ||
import Topic from './topic'; | ||
import PinnedUser from './pinnedUser'; | ||
|
||
export { Meeting, Topic }; | ||
export { Meeting, Topic, PinnedUser }; |
27 changes: 27 additions & 0 deletions
27
packages/plugin-meetings-api/src/graphql/resolvers/mutations/pinnedUser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IContext } from '../../../messageBroker'; | ||
|
||
const pinnedUserMutations = { | ||
// /** | ||
// * Creates a new pinnedUser | ||
// */ | ||
async meetingPinnedUserAdd( | ||
_root, | ||
{ pinnedUserIds }, | ||
{ models, user }: IContext | ||
) { | ||
return await models.PinnedUsers.createPinnedUser(pinnedUserIds, user); | ||
}, | ||
|
||
// /** | ||
// * Edits a pinnedUser | ||
// */ | ||
async meetingPinnedUserEdit( | ||
_root, | ||
{ pinnedUserIds }, | ||
{ models, user }: IContext | ||
) { | ||
return models.PinnedUsers.updatePinnedUser(pinnedUserIds, user); | ||
} | ||
}; | ||
|
||
export default pinnedUserMutations; |
4 changes: 3 additions & 1 deletion
4
packages/plugin-meetings-api/src/graphql/resolvers/queries/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import meetingQueries from './meeting'; | ||
import pinnedUserQueries from './pinnedUser'; | ||
|
||
export default { | ||
...meetingQueries | ||
...meetingQueries, | ||
...pinnedUserQueries | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/plugin-meetings-api/src/graphql/resolvers/queries/pinnedUser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { paginate } from '@erxes/api-utils/src'; | ||
import { IContext } from '../../../messageBroker'; | ||
|
||
const pinnedUserQueries = { | ||
async meetingPinnedUsers(_root, {}, { models, user }: IContext) { | ||
return await paginate(models.PinnedUsers.findOne({ userId: user._id }), {}); | ||
} | ||
}; | ||
|
||
export default pinnedUserQueries; |
11 changes: 11 additions & 0 deletions
11
packages/plugin-meetings-api/src/graphql/schema/pinnedUser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const params = ` | ||
pinnedUserIds: [String] | ||
`; | ||
export const mutations = ` | ||
meetingPinnedUserAdd(${params}): PinnedUsers | ||
meetingPinnedUserEdit(${params}): PinnedUsers | ||
`; | ||
|
||
export const queries = ` | ||
meetingPinnedUsers: PinnedUsers | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/plugin-meetings-api/src/models/definitions/pinnerUser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Schema, Document } from 'mongoose'; | ||
import { field } from './utils'; | ||
|
||
export interface IPinnedUser { | ||
userId: string; | ||
pinnedUserIds: string; | ||
} | ||
export interface IPinnedUserDocument extends IPinnedUser, Document { | ||
_id: String; | ||
} | ||
|
||
export const pinnedUserSchema = new Schema({ | ||
_id: field({ pkey: true }), | ||
userId: field({ pkey: true }), | ||
pinnedUserIds: field({ type: [String] }) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Model } from 'mongoose'; | ||
import { IModels } from '../connectionResolver'; | ||
import { IUser } from '@erxes/api-utils/src/types'; | ||
import { | ||
IPinnedUserDocument, | ||
pinnedUserSchema | ||
} from './definitions/pinnerUser'; | ||
import { checkLogin } from '@erxes/api-utils/src'; | ||
|
||
export interface IPinnedUserModel extends Model<IPinnedUserDocument> { | ||
createPinnedUser( | ||
pinnedUserIds: String[], | ||
user: IUser | ||
): Promise<IPinnedUserDocument>; | ||
updatePinnedUser( | ||
pinnedUserIds: String[], | ||
user: IUser | ||
): Promise<IPinnedUserDocument>; | ||
} | ||
|
||
export const loadPinnedUserClass = (model: IModels) => { | ||
class PinnedUser { | ||
// create | ||
public static async createPinnedUser(pinnedUserIds, user) { | ||
return await model.PinnedUsers.create({ | ||
pinnedUserIds, | ||
userId: user._id | ||
}); | ||
} | ||
|
||
// update | ||
public static async updatePinnedUser(pinnedUserIds, user) { | ||
return await model.PinnedUsers.updateOne( | ||
{ userId: user._id }, | ||
{ $set: { pinnedUserIds } } | ||
).then(err => console.error(err)); | ||
} | ||
} | ||
|
||
pinnedUserSchema.loadClass(PinnedUser); | ||
|
||
return pinnedUserSchema; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/plugin-meetings-ui/src/components/myCalendar/ChooseOwnerForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, ControlLabel, Form, SelectTeamMembers } from '@erxes/ui/src'; | ||
import FormGroup from '@erxes/ui/src/components/form/Group'; | ||
import { ModalFooter } from '@erxes/ui/src/styles/main'; | ||
import { IButtonMutateProps } from '@erxes/ui/src/types'; | ||
|
||
type Props = { | ||
closeModal: () => void; | ||
pinnedUserIds: string[]; | ||
renderButton: (props: IButtonMutateProps) => JSX.Element; | ||
}; | ||
const ChooseOwnerForm = (props: Props) => { | ||
const { pinnedUserIds } = props; | ||
|
||
const [pinnedIds, setPinnedUserIds] = useState([pinnedUserIds] || []); | ||
|
||
const generateDoc = values => { | ||
const finalValues = values; | ||
|
||
if (pinnedIds) { | ||
finalValues.pinnedUserIds = pinnedIds; | ||
} | ||
return { | ||
...finalValues | ||
}; | ||
}; | ||
|
||
const onUserSelect = users => { | ||
setPinnedUserIds(users); | ||
}; | ||
|
||
const renderContent = formProps => { | ||
const { closeModal, renderButton } = props; | ||
const { values, isSubmitted } = formProps; | ||
const object = pinnedUserIds; | ||
|
||
return ( | ||
<> | ||
<FormGroup> | ||
<div style={{ marginBottom: '0' }}> | ||
<ControlLabel>Team members </ControlLabel> | ||
<div style={{ width: '100%' }}> | ||
<SelectTeamMembers | ||
initialValue={pinnedUserIds} | ||
customField="userIds" | ||
filterParams={{}} | ||
label={'Select team member'} | ||
onSelect={onUserSelect} | ||
name="userId" | ||
/> | ||
</div> | ||
</div> | ||
</FormGroup> | ||
<ModalFooter id={'AddTeamMembersButtons'}> | ||
<Button btnStyle="simple" onClick={closeModal} icon="times-circle"> | ||
Cancel | ||
</Button> | ||
|
||
{renderButton({ | ||
passedName: 'Pinned Users', | ||
values: generateDoc(values), | ||
isSubmitted, | ||
callback: closeModal, | ||
object: object | ||
})} | ||
</ModalFooter> | ||
</> | ||
); | ||
}; | ||
|
||
return <Form renderContent={renderContent} />; | ||
}; | ||
|
||
export default ChooseOwnerForm; |
Oops, something went wrong.