Skip to content
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

Display download failure modal in Tag and Member Page #49594

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ function declineJoinRequest(reportID: string, reportAction: OnyxEntry<ReportActi
API.write(WRITE_COMMANDS.DECLINE_JOIN_REQUEST, parameters, {optimisticData, failureData, successData});
}

function downloadMembersCSV(policyID: string) {
function downloadMembersCSV(policyID: string, onDownloadFailed: () => void) {
const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_MEMBERS_CSV, {
policyID,
});
Expand All @@ -899,7 +899,7 @@ function downloadMembersCSV(policyID: string) {
formData.append(key, String(value));
});

fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_MEMBERS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST);
fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_MEMBERS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}

export {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ function setPolicyTagApprover(policyID: string, tag: string, approver: string) {
API.write(WRITE_COMMANDS.SET_POLICY_TAG_APPROVER, parameters, onyxData);
}

function downloadTagsCSV(policyID: string) {
function downloadTagsCSV(policyID: string, onDownloadFailed: () => void) {
const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_TAGS_CSV, {
policyID,
});
Expand All @@ -1001,7 +1001,7 @@ function downloadTagsCSV(policyID: string) {
formData.append(key, String(value));
});

fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_TAGS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST);
fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_TAGS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}

export {
Expand Down
20 changes: 18 additions & 2 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Button from '@components/Button';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import type {DropdownOption, WorkspaceMemberBulkActionType} from '@components/ButtonWithDropdownMenu/types';
import ConfirmModal from '@components/ConfirmModal';
import DecisionModal from '@components/DecisionModal';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import MessagesRow from '@components/MessagesRow';
Expand Down Expand Up @@ -78,10 +79,11 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
const prevAccountIDs = usePrevious(accountIDs);
const textInputRef = useRef<TextInput>(null);
const [isOfflineModalVisible, setIsOfflineModalVisible] = useState(false);
const [isDownloadFailureModalVisible, setIsDownloadFailureModalVisible] = useState(false);
const isOfflineAndNoMemberDataAvailable = isEmptyObject(policy?.employeeList) && isOffline;
const prevPersonalDetails = usePrevious(personalDetails);
const {translate, formatPhoneNumber, preferredLocale} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);
const isLoading = useMemo(
() => !isOfflineAndNoMemberDataAvailable && (!OptionsListUtils.isPersonalDetailsReady(personalDetails) || isEmptyObject(policy?.employeeList)),
Expand Down Expand Up @@ -583,7 +585,12 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
Modal.close(() => setIsOfflineModalVisible(true));
return;
}
Member.downloadMembersCSV(policyID);

Modal.close(() => {
Member.downloadMembersCSV(policyID, () => {
setIsDownloadFailureModalVisible(true);
});
});
},
},
];
Expand Down Expand Up @@ -646,6 +653,15 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson
});
}}
/>
<DecisionModal
title={translate('common.downloadFailedTitle')}
prompt={translate('common.downloadFailedDescription')}
isSmallScreenWidth={isSmallScreenWidth}
onSecondOptionSubmit={() => setIsDownloadFailureModalVisible(false)}
secondOptionText={translate('common.buttonConfirm')}
isVisible={isDownloadFailureModalVisible}
onClose={() => setIsDownloadFailureModalVisible(false)}
/>
<View style={[styles.w100, styles.flex1]}>
<SelectionListWithModal
ref={selectionListRef}
Expand Down
19 changes: 17 additions & 2 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Button from '@components/Button';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
import ConfirmModal from '@components/ConfirmModal';
import DecisionModal from '@components/DecisionModal';
import EmptyStateComponent from '@components/EmptyStateComponent';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
Expand Down Expand Up @@ -50,12 +51,13 @@ import type {PolicyTag, PolicyTagList, TagListItem} from './types';
type WorkspaceTagsPageProps = StackScreenProps<FullScreenNavigatorParamList, typeof SCREENS.WORKSPACE.TAGS>;

function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const {windowWidth} = useWindowDimensions();
const [selectedTags, setSelectedTags] = useState<Record<string, boolean>>({});
const [isDownloadFailureModalVisible, setIsDownloadFailureModalVisible] = useState(false);
const [isDeleteTagsConfirmModalVisible, setIsDeleteTagsConfirmModalVisible] = useState(false);
const [isOfflineModalVisible, setIsOfflineModalVisible] = useState(false);
const isFocused = useIsFocused();
Expand Down Expand Up @@ -316,7 +318,11 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
Modal.close(() => setIsOfflineModalVisible(true));
return;
}
Tag.downloadTagsCSV(policyID);
Modal.close(() => {
Tag.downloadTagsCSV(policyID, () => {
setIsDownloadFailureModalVisible(true);
});
});
},
});
}
Expand Down Expand Up @@ -435,6 +441,15 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
/>
<DecisionModal
title={translate('common.downloadFailedTitle')}
prompt={translate('common.downloadFailedDescription')}
isSmallScreenWidth={isSmallScreenWidth}
onSecondOptionSubmit={() => setIsDownloadFailureModalVisible(false)}
secondOptionText={translate('common.buttonConfirm')}
isVisible={isDownloadFailureModalVisible}
onClose={() => setIsDownloadFailureModalVisible(false)}
/>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
Expand Down
Loading