-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add import and export CSV flow for Members #48876
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
Merged
madmax330
merged 28 commits into
Expensify:main
from
software-mansion-labs:Guccio163/import-members-csv
Sep 20, 2024
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3165104
Add import flow to Members page
filip-solecki be229ed
Merge branch 'filip-solecki/import-categories-csv' into filip-solecki…
filip-solecki f4b6f46
Fix members import
filip-solecki 2c54554
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 93e0e23
ts fix
Guccio163 8ca6b73
adding fixes after categories
Guccio163 5f98deb
add members export
Guccio163 6d0acbb
Update src/libs/actions/Policy/Member.ts
Guccio163 3b656b9
review fixes
Guccio163 b375206
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 f9860d0
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 16d3f65
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 77eba31
Merge branch 'main' into Guccio163/import-members-csv
blazejkustra 333a89a
Migrate withOnyx on members page
blazejkustra dc88ca4
Merge branch 'main' into Guccio163/import-members-csv
blazejkustra 182eb3c
Merge branch 'main' into Guccio163/import-members-csv
blazejkustra 8af21ea
review comments
Guccio163 5c079e9
fix typo
Guccio163 5476cd2
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 92e6745
functions moved to utils
Guccio163 2deb46b
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 38ab688
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 656a3d7
resolve typecheck
Guccio163 213f5fa
unused translation
Guccio163 7861f4f
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 a36596b
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 5e25def
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 233388d
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,6 @@ | ||
type ExportMembersSpreadsheetParams = { | ||
/** ID of the policy */ | ||
policyID: string; | ||
}; | ||
|
||
export default ExportMembersSpreadsheetParams; |
This file contains hidden or 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 @@ | ||
type ImportMembersSpreadsheetParams = { | ||
policyID: string; | ||
/** | ||
* Stringified JSON object with type of following structure: | ||
* Array<{email: string, role: string}> | ||
*/ | ||
employees: string; | ||
}; | ||
|
||
export default ImportMembersSpreadsheetParams; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -10,8 +10,12 @@ import type { | |
UpdateWorkspaceMembersRoleParams, | ||
} from '@libs/API/parameters'; | ||
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; | ||
import * as ApiUtils from '@libs/ApiUtils'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import fileDownload from '@libs/fileDownload'; | ||
import {translateLocal} from '@libs/Localize'; | ||
import Log from '@libs/Log'; | ||
import enhanceParameters from '@libs/Network/enhanceParameters'; | ||
import Parser from '@libs/Parser'; | ||
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; | ||
import * as PhoneNumber from '@libs/PhoneNumber'; | ||
|
@@ -23,6 +27,7 @@ import type {InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, PolicyEmplo | |
import type {PendingAction} from '@src/types/onyx/OnyxCommon'; | ||
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage'; | ||
import type {Attributes, Rate} from '@src/types/onyx/Policy'; | ||
import type {OnyxData} from '@src/types/onyx/Request'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import {createPolicyExpenseChats} from './Policy'; | ||
|
||
|
@@ -167,6 +172,36 @@ function buildAnnounceRoomMembersOnyxData(policyID: string, accountIDs: number[] | |
}); | ||
return announceRoomMembers; | ||
} | ||
/** | ||
* Updates the import spreadsheet data according to the result of the import | ||
*/ | ||
function updateImportSpreadsheetData(membersLength: number): OnyxData { | ||
const onyxData: OnyxData = { | ||
successData: [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.IMPORTED_SPREADSHEET, | ||
value: { | ||
shouldFinalModalBeOpened: true, | ||
importFinalModal: {title: translateLocal('spreadsheet.importSuccessfullTitle'), prompt: translateLocal('spreadsheet.importMembersSuccessfullDescription', membersLength)}, | ||
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. Not sure if it is considered a bug, but we improved the messages to show exactly how many members were added and how many updated: #56941 |
||
}, | ||
}, | ||
], | ||
|
||
failureData: [ | ||
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: ONYXKEYS.IMPORTED_SPREADSHEET, | ||
value: { | ||
shouldFinalModalBeOpened: true, | ||
importFinalModal: {title: translateLocal('spreadsheet.importFailedTitle'), prompt: translateLocal('spreadsheet.importFailedDescription')}, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
return onyxData; | ||
} | ||
|
||
/** | ||
* Build optimistic data for removing users from the announcement room | ||
|
@@ -640,6 +675,22 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccount | |
API.write(WRITE_COMMANDS.ADD_MEMBERS_TO_WORKSPACE, params, {optimisticData, successData, failureData}); | ||
} | ||
|
||
type PolicyMember = { | ||
email: string; | ||
role: string; | ||
}; | ||
|
||
function importPolicyMembers(policyID: string, members: PolicyMember[]) { | ||
const onyxData = updateImportSpreadsheetData(members.length); | ||
|
||
const parameters = { | ||
policyID, | ||
employees: JSON.stringify(members.map((member) => ({email: member.email, role: member.role}))), | ||
}; | ||
|
||
API.write(WRITE_COMMANDS.IMPORT_MEMBERS_SPREADSHEET, parameters, onyxData); | ||
} | ||
|
||
/** | ||
* Invite member to the specified policyID | ||
* Please see https://github.com/Expensify/App/blob/main/README.md#Security for more details | ||
|
@@ -836,6 +887,21 @@ function declineJoinRequest(reportID: string, reportAction: OnyxEntry<ReportActi | |
API.write(WRITE_COMMANDS.DECLINE_JOIN_REQUEST, parameters, {optimisticData, failureData, successData}); | ||
} | ||
|
||
function downloadMembersCSV(policyID: string) { | ||
Guccio163 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_MEMBERS_CSV, { | ||
policyID, | ||
}); | ||
|
||
const fileName = 'Members.csv'; | ||
|
||
const formData = new FormData(); | ||
Object.entries(finalParameters).forEach(([key, value]) => { | ||
formData.append(key, String(value)); | ||
}); | ||
|
||
fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_MEMBERS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST); | ||
} | ||
|
||
export { | ||
removeMembers, | ||
updateWorkspaceMembersRole, | ||
|
@@ -850,6 +916,8 @@ export { | |
acceptJoinRequest, | ||
declineJoinRequest, | ||
isApprover, | ||
importPolicyMembers, | ||
downloadMembersCSV, | ||
}; | ||
|
||
export type {NewCustomUnit}; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.