Skip to content

Commit

Permalink
Fix picking payout method when not admin of payee
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavlrsn committed Dec 19, 2024
1 parent dbe8a55 commit f208618
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion components/expenses/EditExpenseDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const EditPayee = ({ expense, onSubmit }) => {
const formRef = React.useRef<HTMLFormElement>();
const startOptions = React.useRef({
expenseId: expense.legacyId,
allowInvite: false,
isInlineEdit: true,
});
const transformedOnSubmit = React.useCallback(
async (values, h, formOptions) => {
Expand Down Expand Up @@ -150,6 +150,7 @@ const EditPayoutMethod = ({ expense, onSubmit }) => {
const formRef = React.useRef<HTMLFormElement>();
const startOptions = React.useRef({
expenseId: expense.legacyId,
isInlineEdit: true,
});
const transformedOnSubmit = React.useCallback(
async (values, h, formOptions) => {
Expand Down Expand Up @@ -232,6 +233,7 @@ const EditAttachments = ({ expense, onSubmit }) => {
const formRef = React.useRef<HTMLFormElement>();
const startOptions = React.useRef({
expenseId: expense.legacyId,
isInlineEdit: true,
});
const transformedOnSubmit = values => {
const editValues = {
Expand Down Expand Up @@ -283,6 +285,7 @@ const EditExpenseItems = ({ expense, onSubmit }) => {
const formRef = React.useRef<HTMLFormElement>();
const startOptions = React.useRef({
expenseId: expense.legacyId,
isInlineEdit: true,
});
const transformedOnSubmit = values => {
const editValues = {
Expand Down
1 change: 0 additions & 1 deletion components/submit-expense/SubmitExpenseFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ function ExpenseFormikContainer(props: {
draftKey: props.draftKey,
duplicateExpense: props.duplicateExpense,
expenseId: props.expenseId,
allowInvite: true,
});

const [activeStep, setActiveStep] = React.useState(Step.WHO_IS_PAYING);
Expand Down
8 changes: 5 additions & 3 deletions components/submit-expense/useExpenseForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,9 @@ async function buildFormOptions(
options.payoutMethod = values.newPayoutMethod;
}

options.isAdminOfPayee = options.payoutProfiles.some(p => p.slug === values.payeeSlug);
// Allow setting this flag to true with the `isInlineEdit` flag in start options to enable full editing experience (i.e. editing payotu method)
options.isAdminOfPayee =
startOptions.isInlineEdit || options.payoutProfiles.some(p => p.slug === values.payeeSlug);
}

if (options.payoutMethod) {
Expand All @@ -1283,7 +1285,7 @@ async function buildFormOptions(

options.allowExpenseItemAttachment = values.expenseTypeOption === ExpenseType.RECEIPT;

options.allowInvite = startOptions.allowInvite;
options.allowInvite = !startOptions.isInlineEdit;

if (values.expenseTypeOption === ExpenseType.INVOICE) {
if (accountHasVAT(account as any, host as any)) {
Expand Down Expand Up @@ -1341,7 +1343,7 @@ type ExpenseFormStartOptions = {
duplicateExpense?: boolean;
expenseId?: number;
draftKey?: string;
allowInvite?: boolean;
isInlineEdit?: boolean;
};

export function useExpenseForm(opts: {
Expand Down

0 comments on commit f208618

Please sign in to comment.