Skip to content

Commit 551064f

Browse files
committed
debt(Expense): remove legacy flow
1 parent 5d3eeda commit 551064f

37 files changed

+51
-1523
lines changed

components/collective-navbar/ActionsMenu.js

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@ import { AttachMoney } from '@styled-icons/material/AttachMoney';
88
import { Settings } from '@styled-icons/material/Settings';
99
import { Stack } from '@styled-icons/remix-line/Stack';
1010
import { pickBy } from 'lodash';
11-
import { useRouter } from 'next/router';
1211
import { FormattedMessage } from 'react-intl';
1312
import styled, { css } from 'styled-components';
1413

1514
import { getContributeRoute } from '../../lib/collective';
16-
import { isSupportedExpenseType } from '../../lib/expenses';
17-
import { ExpenseType } from '../../lib/graphql/types/v2/graphql';
18-
import { PREVIEW_FEATURE_KEYS } from '../../lib/preview-features';
1915
import { getCollectivePageRoute, getDashboardRoute } from '../../lib/url-helpers';
20-
import { parseToBoolean } from '@/lib/utils';
2116

2217
import ActionButton from '../ActionButton';
2318
import AddFundsBtn from '../AddFundsBtn';
@@ -183,16 +178,6 @@ const CollectiveNavbarActionsMenu = ({
183178
const enabledCTAs = Object.keys(pickBy(callsToAction, Boolean));
184179
const isEmpty = enabledCTAs.length < 1;
185180
const hasOnlyOneHiddenCTA = enabledCTAs.length === 1 && hiddenActionForNonMobile === enabledCTAs[0];
186-
const router = useRouter();
187-
188-
const newExpenseFlowOptedOut = parseToBoolean(router?.query?.forceLegacyFlow);
189-
const isNewGrantFlowEnabled =
190-
!newExpenseFlowOptedOut && LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW);
191-
192-
const isNewExpenseFlowEnabled =
193-
!newExpenseFlowOptedOut &&
194-
LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW) &&
195-
(!isSupportedExpenseType(collective, ExpenseType.GRANT) || isNewGrantFlowEnabled);
196181

197182
// Do not render the menu if there are no available CTAs
198183
if (isEmpty) {
@@ -241,33 +226,17 @@ const CollectiveNavbarActionsMenu = ({
241226
)}
242227
{callsToAction.hasSubmitExpense && (
243228
<MenuItem isHiddenOnMobile={hiddenActionForNonMobile === NAVBAR_ACTION_TYPE.SUBMIT_EXPENSE}>
244-
{isNewExpenseFlowEnabled ? (
245-
<StyledLink onClick={onOpenSubmitExpenseModalClick}>
246-
<Container p={ITEM_PADDING}>
247-
<Receipt size="20px" />
248-
<FormattedMessage id="ExpenseForm.Submit" defaultMessage="Submit expense" />
249-
</Container>
250-
</StyledLink>
251-
) : (
252-
<StyledLink
253-
data-cy="submit-expense-dropdown"
254-
as={Link}
255-
href={`${getCollectivePageRoute(collective)}/expenses/new?forceLegacyFlow=true`}
256-
>
257-
<Container p={ITEM_PADDING}>
258-
<Receipt size="20px" />
259-
<FormattedMessage id="ExpenseForm.Submit" defaultMessage="Submit expense" />
260-
</Container>
261-
</StyledLink>
262-
)}
229+
<StyledLink onClick={onOpenSubmitExpenseModalClick}>
230+
<Container p={ITEM_PADDING}>
231+
<Receipt size="20px" />
232+
<FormattedMessage id="ExpenseForm.Submit" defaultMessage="Submit expense" />
233+
</Container>
234+
</StyledLink>
263235
</MenuItem>
264236
)}
265237
{callsToAction.hasRequestGrant && (
266238
<MenuItem py={1} isHiddenOnMobile={hiddenActionForNonMobile === NAVBAR_ACTION_TYPE.REQUEST_GRANT}>
267-
<StyledLink
268-
as={Link}
269-
href={`${getCollectivePageRoute(collective)}/${isNewGrantFlowEnabled ? 'grants' : 'expenses'}/new`}
270-
>
239+
<StyledLink as={Link} href={`${getCollectivePageRoute(collective)}/grants/new`}>
271240
<Container p={ITEM_PADDING}>
272241
<MoneyCheckAlt size="20px" />
273242
<FormattedMessage id="ExpenseForm.Type.Request" defaultMessage="Request Grant" />

components/collective-navbar/index.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,6 @@ const CollectiveNavbar = ({
508508

509509
const loading = isLoading || dataLoading;
510510

511-
const isNewGrantFlowEnabled = LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW);
512-
513-
const isNewExpenseFlowEnabled =
514-
LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW) &&
515-
(!isSupportedExpenseType(collective, ExpenseType.GRANT) || isNewGrantFlowEnabled);
516-
517511
const isAllowedAddFunds = Boolean(data?.account?.permissions?.addFunds?.allowed);
518512
const sections = React.useMemo(() => {
519513
return sectionsFromParent || getFilteredSectionsForCollective(collective, isAdmin, isHostAdmin);
@@ -531,23 +525,11 @@ const CollectiveNavbar = ({
531525
...callsToAction,
532526
};
533527
const actionsArray = Object.keys(pickBy(callsToAction, Boolean));
534-
const mainAction = getMainAction(
535-
collective,
536-
actionsArray,
537-
LoggedInUser,
538-
isNewExpenseFlowEnabled,
539-
isNewGrantFlowEnabled,
540-
() => setIsSubmitExpenseModalOpen(true),
541-
);
528+
const mainAction = getMainAction(collective, actionsArray, LoggedInUser, () => setIsSubmitExpenseModalOpen(true));
542529
const secondAction =
543530
actionsArray.length === 2 &&
544-
getMainAction(
545-
collective,
546-
without(actionsArray, mainAction?.type),
547-
LoggedInUser,
548-
isNewExpenseFlowEnabled,
549-
isNewGrantFlowEnabled,
550-
() => setIsSubmitExpenseModalOpen(true),
531+
getMainAction(collective, without(actionsArray, mainAction?.type), LoggedInUser, () =>
532+
setIsSubmitExpenseModalOpen(true),
551533
);
552534
const navbarRef = useRef(undefined);
553535
const mainContainerRef = useRef(undefined);

components/dashboard/sections/expenses/ReceivedExpenses.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import {
1414
ExpenseType,
1515
PayoutMethodType,
1616
} from '../../../../lib/graphql/types/v2/schema';
17-
import useLoggedInUser from '../../../../lib/hooks/useLoggedInUser';
1817
import useQueryFilter from '../../../../lib/hooks/useQueryFilter';
19-
import { PREVIEW_FEATURE_KEYS } from '../../../../lib/preview-features';
2018
import { i18nExpenseType } from '@/lib/i18n/expense';
2119
import { sortSelectOptions } from '@/lib/utils';
2220

@@ -111,7 +109,6 @@ const ROUTE_PARAMS = ['slug', 'section', 'subpath'];
111109
const ReceivedExpenses = ({ accountSlug }: DashboardSectionProps) => {
112110
const router = useRouter();
113111
const [isExpenseFlowOpen, setIsExpenseFlowOpen] = React.useState(false);
114-
const { LoggedInUser } = useLoggedInUser();
115112

116113
const {
117114
data: metadata,
@@ -161,9 +158,6 @@ const ReceivedExpenses = ({ accountSlug }: DashboardSectionProps) => {
161158
context: API_V2_CONTEXT,
162159
});
163160

164-
const hasNewSubmitExpenseFlow =
165-
LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW) || router.query.newExpenseFlowEnabled;
166-
167161
const pageRoute = `/dashboard/${accountSlug}/expenses`;
168162

169163
return (
@@ -173,11 +167,9 @@ const ReceivedExpenses = ({ accountSlug }: DashboardSectionProps) => {
173167
title={<FormattedMessage defaultMessage="Received Expenses" id="1c0Y31" />}
174168
description={<FormattedMessage defaultMessage="Expenses submitted to your account." id="0I3Lbj" />}
175169
actions={
176-
hasNewSubmitExpenseFlow ? (
177-
<Button onClick={() => setIsExpenseFlowOpen(true)} size="sm" className="gap-1">
178-
<FormattedMessage defaultMessage="New expense" id="pNn/g+" />
179-
</Button>
180-
) : null
170+
<Button onClick={() => setIsExpenseFlowOpen(true)} size="sm" className="gap-1">
171+
<FormattedMessage defaultMessage="New expense" id="pNn/g+" />
172+
</Button>
181173
}
182174
/>
183175
{isSelfHosted && (

components/dashboard/sections/expenses/SubmittedExpenses.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ const SubmittedExpenses = ({ accountSlug }: DashboardSectionProps) => {
9494
accountingCategoryKinds: ExpenseAccountingCategoryKinds,
9595
};
9696

97-
const hasNewSubmitExpenseFlow =
98-
LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW) || router.query.newExpenseFlowEnabled;
99-
10097
const pageRoute = `/dashboard/${accountSlug}/submitted-expenses`;
10198

10299
if (error) {
@@ -112,18 +109,16 @@ const SubmittedExpenses = ({ accountSlug }: DashboardSectionProps) => {
112109
<FormattedMessage defaultMessage="Expenses that you have submitted to other accounts." id="aKfm6V" />
113110
}
114111
actions={
115-
hasNewSubmitExpenseFlow ? (
116-
<Button
117-
onClick={() => {
118-
setDuplicateExpenseId(null);
119-
setIsExpenseFlowOpen(true);
120-
}}
121-
size="sm"
122-
className="gap-1"
123-
>
124-
<FormattedMessage defaultMessage="New expense" id="pNn/g+" />
125-
</Button>
126-
) : null
112+
<Button
113+
onClick={() => {
114+
setDuplicateExpenseId(null);
115+
setIsExpenseFlowOpen(true);
116+
}}
117+
size="sm"
118+
className="gap-1"
119+
>
120+
<FormattedMessage defaultMessage="New expense" id="pNn/g+" />
121+
</Button>
127122
}
128123
/>
129124
<Filterbar {...queryFilter} meta={filterMeta} />

components/expenses/Expense.tsx

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { useWindowResize, VIEWPORTS } from '../../lib/hooks/useWindowResize';
2626
import { itemHasOCR } from './lib/ocr';
2727
import { isFeatureEnabled } from '@/lib/allowed-features';
2828
import type { AccountWithHost, Expense as ExpenseType } from '@/lib/graphql/types/v2/schema';
29-
import { PREVIEW_FEATURE_KEYS } from '@/lib/preview-features';
3029
import { getCollectivePageRoute } from '@/lib/url-helpers';
3130

3231
import ConfirmationModal from '../ConfirmationModal';
@@ -160,18 +159,9 @@ function Expense(props: ExpenseProps) {
160159
enableKeyboardShortcuts,
161160
onClose,
162161
} = props;
163-
const { LoggedInUser, loadingLoggedInUser } = useLoggedInUser();
162+
const { loadingLoggedInUser } = useLoggedInUser();
164163
const intl = useIntl();
165164
const router = useRouter();
166-
167-
const isNewExpenseSubmissionFlow =
168-
(([expenseTypes.INVOICE, expenseTypes.RECEIPT] as string[]).includes(data?.expense?.type) &&
169-
((LoggedInUser && LoggedInUser.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW)) ||
170-
router.query.newExpenseFlowEnabled)) ||
171-
(([expenseTypes.GRANT] as string[]).includes(data?.expense?.type) &&
172-
((LoggedInUser && LoggedInUser.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW)) ||
173-
router.query.newGrantFlowEnabled));
174-
175165
const [isSubmissionFlowOpen, setIsSubmissionFlowOpen] = React.useState(false);
176166

177167
const onContinueSubmissionClick = React.useCallback(() => {
@@ -191,12 +181,7 @@ function Expense(props: ExpenseProps) {
191181

192182
const [state, setState] = useState({
193183
error: error || null,
194-
status:
195-
draftKey && data?.expense?.status === ExpenseStatus.DRAFT
196-
? isNewExpenseSubmissionFlow
197-
? PAGE_STATUS.VIEW
198-
: PAGE_STATUS.EDIT
199-
: PAGE_STATUS.VIEW,
184+
status: draftKey && data?.expense?.status === ExpenseStatus.DRAFT ? PAGE_STATUS.VIEW : PAGE_STATUS.EDIT,
200185
editedExpense: null,
201186
isSubmitting: false,
202187
isPollingEnabled: true,
@@ -216,17 +201,6 @@ function Expense(props: ExpenseProps) {
216201
const drawerActionsContainer = useDrawerActionsContainer();
217202

218203
useEffect(() => {
219-
const shouldEditDraft = isNewExpenseSubmissionFlow
220-
? false
221-
: data?.expense?.status === ExpenseStatus.DRAFT && draftKey;
222-
if (shouldEditDraft) {
223-
setState(state => ({
224-
...state,
225-
status: PAGE_STATUS.EDIT,
226-
editedExpense: data?.expense,
227-
}));
228-
}
229-
230204
handlePolling();
231205
document.addEventListener('mousemove', handlePolling);
232206

@@ -266,16 +240,11 @@ function Expense(props: ExpenseProps) {
266240

267241
// Update status when data or draftKey changes
268242
useEffect(() => {
269-
const status =
270-
draftKey && data?.expense?.status === ExpenseStatus.DRAFT
271-
? isNewExpenseSubmissionFlow
272-
? PAGE_STATUS.VIEW
273-
: PAGE_STATUS.EDIT
274-
: PAGE_STATUS.VIEW;
243+
const status = draftKey && data?.expense?.status === ExpenseStatus.DRAFT ? PAGE_STATUS.VIEW : PAGE_STATUS.EDIT;
275244
if (status !== state.status) {
276245
setState(state => ({ ...state, status }));
277246
}
278-
}, [props.data, draftKey, isNewExpenseSubmissionFlow]);
247+
}, [props.data, draftKey]);
279248

280249
// Scroll to expense's top when changing status
281250
const prevState = usePrevious(state);
@@ -617,27 +586,22 @@ function Expense(props: ExpenseProps) {
617586
)}
618587
{status !== PAGE_STATUS.EDIT && (
619588
<Box mb={3}>
620-
{isNewExpenseSubmissionFlow &&
621-
(expense?.permissions?.canDeclineExpenseInvite ||
622-
(expense?.status === ExpenseStatus.DRAFT &&
623-
!isRecurring &&
624-
draftKey &&
625-
expense?.draft?.recipientNote)) && (
626-
<ExpenseInviteWelcome
627-
onContinueSubmissionClick={onContinueSubmissionClick}
628-
className="mb-6"
629-
expense={expense}
630-
draftKey={draftKey}
631-
/>
632-
)}
589+
{(expense?.permissions?.canDeclineExpenseInvite ||
590+
(expense?.status === ExpenseStatus.DRAFT && !isRecurring && draftKey && expense?.draft?.recipientNote)) && (
591+
<ExpenseInviteWelcome
592+
onContinueSubmissionClick={onContinueSubmissionClick}
593+
className="mb-6"
594+
expense={expense}
595+
draftKey={draftKey}
596+
/>
597+
)}
633598
<ExpenseSummary
634599
expense={status === PAGE_STATUS.EDIT_SUMMARY ? editedExpense : expense}
635600
host={host}
636601
isLoading={loading || !expense}
637602
isEditing={status === PAGE_STATUS.EDIT_SUMMARY}
638603
isLoadingLoggedInUser={loadingLoggedInUser || isRefetchingDataForUser}
639604
collective={collective}
640-
onEdit={onEditBtnClick}
641605
onDelete={onDelete}
642606
canEditTags={get(expense, 'permissions.canEditTags', false)}
643607
showProcessButtons

components/expenses/ExpenseMissingReceiptNotificationBanner.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import React from 'react';
22
import { FormattedMessage, useIntl } from 'react-intl';
33

4-
import useLoggedInUser from '@/lib/hooks/useLoggedInUser';
5-
import { PREVIEW_FEATURE_KEYS } from '@/lib/preview-features';
6-
74
import { Flex } from '../../components/Grid';
85
import MessageBox from '../../components/MessageBox';
96
import StyledButton from '../../components/StyledButton';
@@ -15,11 +12,7 @@ import EditExpenseDialog from './EditExpenseDialog';
1512

1613
const ExpenseMissingReceiptNotificationBanner = props => {
1714
const intl = useIntl();
18-
const { LoggedInUser } = useLoggedInUser();
19-
20-
const { canAttachReceipts } = LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.INLINE_EDIT_EXPENSE)
21-
? props.expense?.permissions || {}
22-
: {};
15+
const { canAttachReceipts } = props.expense?.permissions || {};
2316

2417
return (
2518
<MessageBox py={3} px="26px" mb={4} type="warning">

components/expenses/ExpenseMoreActionsButton.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { Check } from '@styled-icons/feather/Check';
33
import { ChevronDown } from '@styled-icons/feather/ChevronDown/ChevronDown';
44
import { Download as IconDownload } from '@styled-icons/feather/Download';
5-
import { Edit as IconEdit } from '@styled-icons/feather/Edit';
65
import { Flag as FlagIcon } from '@styled-icons/feather/Flag';
76
import { Link as IconLink } from '@styled-icons/feather/Link';
87
import { MinusCircle } from '@styled-icons/feather/MinusCircle';
@@ -22,7 +21,6 @@ import { ExpenseStatus, ExpenseType } from '../../lib/graphql/types/v2/schema';
2221
import useClipboard from '../../lib/hooks/useClipboard';
2322
import useKeyboardKey, { H, I } from '../../lib/hooks/useKeyboardKey';
2423
import useLoggedInUser from '../../lib/hooks/useLoggedInUser';
25-
import { PREVIEW_FEATURE_KEYS } from '../../lib/preview-features';
2624
import { getCollectivePageCanonicalURL, getCollectivePageRoute, getDashboardRoute } from '../../lib/url-helpers';
2725

2826
import { DashboardContext } from '../dashboard/DashboardContext';
@@ -106,7 +104,6 @@ const shouldShowDuplicateExpenseButton = (LoggedInUser, expense) => {
106104
const ExpenseMoreActionsButton = ({
107105
expense,
108106
onError,
109-
onEdit,
110107
isDisabled,
111108
linkAction = 'copy',
112109
onModalToggle,
@@ -153,9 +150,6 @@ const ExpenseMoreActionsButton = ({
153150
});
154151
const { LoggedInUser } = useLoggedInUser();
155152

156-
const hasNewSubmitExpenseFlow =
157-
LoggedInUser?.hasPreviewFeatureEnabled(PREVIEW_FEATURE_KEYS.NEW_EXPENSE_FLOW) || router.query.newExpenseFlowEnabled;
158-
159153
const showDeleteConfirmMoreActions = isOpen => {
160154
setDeleteConfirm(isOpen);
161155
onModalToggle?.(isOpen);
@@ -288,12 +282,6 @@ const ExpenseMoreActionsButton = ({
288282
<FormattedMessage id="actions.delete" defaultMessage="Delete" />
289283
</Action>
290284
)}
291-
{onEdit && permissions.canEdit && (
292-
<Action data-cy="edit-expense-btn" onClick={onEdit} disabled={processExpense.loading || isDisabled}>
293-
<IconEdit size="16px" />
294-
<FormattedMessage id="Edit" defaultMessage="Edit" />
295-
</Action>
296-
)}
297285
{!props.hasAttachedInvoiceFile &&
298286
permissions.canSeeInvoiceInfo &&
299287
[expenseTypes.INVOICE, expenseTypes.SETTLEMENT, expenseTypes.PLATFORM_BILLING].includes(
@@ -353,7 +341,7 @@ const ExpenseMoreActionsButton = ({
353341
<FormattedMessage id="CopyLink" defaultMessage="Copy link" />
354342
)}
355343
</Action>
356-
{hasNewSubmitExpenseFlow && shouldShowDuplicateExpenseButton(LoggedInUser, expense) && (
344+
{shouldShowDuplicateExpenseButton(LoggedInUser, expense) && (
357345
<Action
358346
onClick={() => {
359347
setDuplicateExpenseId(expense.legacyId);

0 commit comments

Comments
 (0)