Skip to content

Commit

Permalink
Merge pull request #42613 from Expensify/hayata-display-delete-button
Browse files Browse the repository at this point in the history
FIX the logic to check if there is an accounting connection in the workspace
  • Loading branch information
lakchote authored May 31, 2024
2 parents e915d36 + 69ae5cf commit da6cafd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function extractPolicyIDFromPath(path: string) {
* Whether the policy has active accounting integration connections
*/
function hasAccountingConnections(policy: OnyxEntry<Policy>) {
return Boolean(policy?.connections);
return !isEmptyObject(policy?.connections);
}

function getPathWithoutPolicyID(path: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const isLoading = !isOffline && policyTags === undefined;

const getHeaderButtons = () => {
const isThereAnyAccountingConnection = Object.keys(policy?.connections ?? {}).length !== 0;
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);

if (selectedTagsArray.length === 0) {
return (
<View style={[styles.w100, styles.flexRow, styles.gap2, isSmallScreenWidth && styles.mb3]}>
{!isThereAnyAccountingConnection && !isMultiLevelTags && (
{!hasAccountingConnections && !isMultiLevelTags && (
<Button
medium
success
Expand All @@ -204,7 +204,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {

const options: Array<DropdownOption<DeepValueOf<typeof CONST.POLICY.TAGS_BULK_ACTION_TYPES>>> = [];

if (!isThereAnyAccountingConnection) {
if (!hasAccountingConnections) {
options.push({
icon: Expensicons.Trashcan,
text: translate(selectedTagsArray.length === 1 ? 'workspace.tags.deleteTag' : 'workspace.tags.deleteTags'),
Expand Down
22 changes: 13 additions & 9 deletions src/pages/workspace/taxes/WorkspaceEditTaxPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function WorkspaceEditTaxPage({
const {windowWidth} = useWindowDimensions();
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
const canEdit = policy && PolicyUtils.canEditTaxRate(policy, taxID);
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);

const toggleTaxRate = () => {
if (!currentTaxRate) {
Expand All @@ -58,14 +59,17 @@ function WorkspaceEditTaxPage({
};

const threeDotsMenuItems: ThreeDotsMenuItem[] = useMemo(
() => [
{
icon: Expensicons.Trashcan,
text: translate('common.delete'),
onSelected: () => setIsDeleteModalVisible(true),
},
],
[translate],
() =>
canEdit && !hasAccountingConnections
? [
{
icon: Expensicons.Trashcan,
text: translate('common.delete'),
onSelected: () => setIsDeleteModalVisible(true),
},
]
: [],
[translate, canEdit, hasAccountingConnections],
);

if (!currentTaxRate) {
Expand All @@ -86,7 +90,7 @@ function WorkspaceEditTaxPage({
<HeaderWithBackButton
title={currentTaxRate?.name}
threeDotsMenuItems={threeDotsMenuItems}
shouldShowThreeDotsButton={!!canEdit && !PolicyUtils.hasAccountingConnections(policy)}
shouldShowThreeDotsButton={threeDotsMenuItems.length > 0}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(windowWidth)}
/>
<OfflineWithFeedback
Expand Down
7 changes: 4 additions & 3 deletions src/pages/workspace/taxes/WorkspaceTaxesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function WorkspaceTaxesPage({
const defaultExternalID = policy?.taxRates?.defaultExternalID;
const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault;
const isFocused = useIsFocused();
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);

const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0;
const isConnectedToQbo = Boolean(policy?.connections?.quickbooksOnline);
Expand Down Expand Up @@ -178,7 +179,7 @@ function WorkspaceTaxesPage({
const dropdownMenuOptions = useMemo(() => {
const isMultiple = selectedTaxesIDs.length > 1;
const options: Array<DropdownOption<WorkspaceTaxRatesBulkActionType>> = [];
if (!PolicyUtils.hasAccountingConnections(policy)) {
if (!hasAccountingConnections) {
options.push({
icon: Expensicons.Trashcan,
text: isMultiple ? translate('workspace.taxes.actions.deleteMultiple') : translate('workspace.taxes.actions.delete'),
Expand Down Expand Up @@ -207,11 +208,11 @@ function WorkspaceTaxesPage({
});
}
return options;
}, [policy, selectedTaxesIDs, toggleTaxes, translate]);
}, [hasAccountingConnections, policy?.taxRates?.taxes, selectedTaxesIDs, toggleTaxes, translate]);

const headerButtons = !selectedTaxesIDs.length ? (
<View style={[styles.w100, styles.flexRow, isSmallScreenWidth && styles.mb3]}>
{!PolicyUtils.hasAccountingConnections(policy) && (
{!hasAccountingConnections && (
<Button
medium
success
Expand Down

0 comments on commit da6cafd

Please sign in to comment.