-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add modal for inviting users to a workspace #3463
Changes from 17 commits
6e72ad1
2a60ac7
e01059d
c255c9e
ba6e9ce
b87c128
89dd12f
41d45d3
39d1b51
0bde5fc
8be51d8
44f095a
04382bb
b92ebaf
5604e30
4023ff8
686db89
6836fe0
d8e8120
2901551
25d16b8
77cc488
7cee97a
04f28fe
cc62bd2
a6d715b
7e5937f
59ab488
ff4f095
f34c715
409f66a
466a9bc
c787e01
4fe596a
5be04c0
ae3fc4a
2b0e575
cdbc397
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import _ from 'underscore'; | ||
import Onyx from 'react-native-onyx'; | ||
import {GetPolicySummaryList} from '../API'; | ||
import {GetPolicySummaryList, GetPolicyList, Policy_Employees_Merge} from '../API'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
|
||
const allPolicies = {}; | ||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.POLICY, | ||
callback: (val, key) => { | ||
if (val && key) { | ||
allPolicies[key] = val; | ||
} | ||
}, | ||
}); | ||
|
||
/** | ||
* Takes a full policy summary that is returned from the policySummaryList and simplifies it so we are only storing | ||
* the pieces of data that we need to in Onyx | ||
|
@@ -17,6 +27,27 @@ function getSimplifiedPolicyObject(fullPolicy) { | |
}; | ||
} | ||
|
||
/** | ||
* Simplifies the policyList response into an object containing an array of emails | ||
* | ||
* @param {Object} fullPolicy | ||
* @returns {Object} | ||
*/ | ||
function getSimplifiedMemberList(fullPolicy) { | ||
const employeeListEmails = _.chain(fullPolicy.value.employeeList) | ||
.pluck('email') | ||
.flatten() | ||
.unique() | ||
.value(); | ||
|
||
return { | ||
employeeList: employeeListEmails, | ||
}; | ||
} | ||
|
||
/** | ||
* Fetches the policySummaryList from the API and saves a simplified version in Onyx | ||
*/ | ||
function getPolicySummaries() { | ||
GetPolicySummaryList() | ||
.then((data) => { | ||
|
@@ -30,7 +61,74 @@ function getPolicySummaries() { | |
}); | ||
} | ||
|
||
/** | ||
* Fetches the policyList from the API and saves a simplified version in Onyx | ||
*/ | ||
function getPolicyList() { | ||
GetPolicyList() | ||
.then((data) => { | ||
if (data.jsonCode === 200) { | ||
const policyDataToStore = _.reduce(data.policyList, (memo, policy) => ({ | ||
...memo, | ||
[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: getSimplifiedMemberList(policy), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB, I wonder if it would be more clear that this is doing a [`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: {employeeList: getSimplifiedMemberList(policy)}, also seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the name of the function to |
||
}), {}); | ||
Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, policyDataToStore); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Merges the passed in login into the specified policy | ||
* | ||
* @param {String} login | ||
* @param {String} welcomeNote | ||
* @param {String} policyID | ||
*/ | ||
function invite(login, welcomeNote, policyID) { | ||
// Optimistically add the user to the policy | ||
const key = `${ONYXKEYS.COLLECTION.POLICY}${policyID}`; | ||
const dataToStore = {}; | ||
dataToStore[key] = { | ||
employeeList: allPolicies[key].employeeList.concat([login]), | ||
}; | ||
|
||
Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, dataToStore) | ||
.then(() => { | ||
const policyDataWithoutLogin = {}; | ||
policyDataWithoutLogin[key] = { | ||
employeeList: _.without(allPolicies[key].employeeList, login), | ||
}; | ||
Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, policyDataWithoutLogin) | ||
.then(() => { | ||
console.debug('done'); | ||
}); | ||
}); | ||
Jag96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Policy_Employees_Merge({ | ||
// employees: JSON.stringify([{email: login}]), | ||
// welcomeNote, | ||
// policyID, | ||
// }) | ||
// .then((data) => { | ||
// // Save data.personalDetails | ||
// if (data.jsonCode !== 200) { | ||
// // TODO: need to match personalDetails to data in PersonalDetails.formatPersonalDetails | ||
// Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, {[login]: data.personalDetails[login]}); | ||
// return; | ||
// } | ||
// | ||
// // If the operation failed, undo the optimistic addition | ||
// const policyDataWithoutLogin = {}; | ||
// policyDataWithoutLogin[key] = { | ||
// employeeList: _.without(allPolicies[key].employeeList, login), | ||
// }; | ||
// Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, policyDataWithoutLogin); | ||
// }); | ||
} | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
getPolicySummaries, | ||
getPolicyList, | ||
invite, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB but maybe a good follow up. I noticed that we are doing this in every file that needs to use
translate()
. Perhaps we should just subscribe to the preferred locale in'../translate.js'
and then we could export the method that already knows what the locale is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good follow-up to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a follow-up PR here: #3716