Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.32k stars 2.76k forks source link

[HOLD for payment 2024-06-28] [$250] Group Chat custom avatar not saved when navigating back to invite members page #40198

Closed marcaaron closed 2 months ago

marcaaron commented 5 months ago

Coming from https://github.com/Expensify/App/pull/39757#issuecomment-2052659550

  1. Create a new group chat
  2. Choose a picture for custom avatar
  3. Go back to member invite page
  4. Proceed again
  5. Create chat

Expected:

Avatar image should be saved.

Actual

Picture is not taken into consideration.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~014f246ab8eb2607ee
  • Upwork Job ID: 1785758481083801600
  • Last Price Increase: 2024-06-05
  • Automatic offers:
    • s77rt | Reviewer | 102700850
    • wildan-m | Contributor | 102700854
Issue OwnerCurrent Issue Owner: @adelekennedy
marcaaron commented 5 months ago

I am guessing this is because the file ref needs to be cached outside the component lifecycle or some other strategy to achieve it. Feels like a minor issue that can be easily solved.

s77rt commented 4 months ago

No progress yet. Focused on QBO

marcaaron commented 4 months ago

Gonna take this one External so we can make some progress.

melvin-bot[bot] commented 4 months ago

Triggered auto assignment to @adelekennedy (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

melvin-bot[bot] commented 4 months ago

Job added to Upwork: https://www.upwork.com/jobs/~014f246ab8eb2607ee

melvin-bot[bot] commented 4 months ago

Current assignee @s77rt is eligible for the External assigner, not assigning anyone new.

neonbhai commented 4 months ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Group Chat custom avatar not saved when navigating back to invite members page

What is the root cause of that problem?

When creating the group, we use the outdated fileRef.current which is undefined when coming back.

https://github.com/Expensify/App/blob/406139cf2120b25c28643f1e728d531fd8848a60/src/pages/NewChatConfirmPage.tsx#L96

What changes do you think we should make in order to solve the problem?

We should use stashedLocalAvatarImage which takes the saved picture from the NEW_GROUP_CHAT_DRAFT Onyx key when creating the groupChat

https://github.com/Expensify/App/blob/406139cf2120b25c28643f1e728d531fd8848a60/src/pages/NewChatConfirmPage.tsx#L107

s77rt commented 4 months ago

@neonbhai Thanks for the proposal. Your RCA makes sense but the solution won't work. In onyx we only store the url and we want to pass the whole image.

s77rt commented 4 months ago

Still looking for proposals

melvin-bot[bot] commented 4 months ago

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

adelekennedy commented 4 months ago

still waiting for proposals - @marcaaron @s77rt is this a more complex issue than originally thought?

s77rt commented 4 months ago

@adelekennedy I didn't check in depth but it shouldn't be that hard, no need to adjust the bounty yet

marcaaron commented 4 months ago

Agree, I think we just haven't found the obvious solution yet - but let's see.

melvin-bot[bot] commented 4 months ago

@s77rt @marcaaron @adelekennedy this issue is now 4 weeks old, please consider:

Thanks!

adelekennedy commented 4 months ago

still waiting

melvin-bot[bot] commented 4 months ago

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

adelekennedy commented 3 months ago

gonna just keep waiting on this as it's pretty edge-casey. Going to move this to weekly so we don't keep getting dinged

melvin-bot[bot] commented 3 months ago

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

s77rt commented 3 months ago

Still looking for proposals...

melvin-bot[bot] commented 3 months ago

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

adelekennedy commented 3 months ago

still pending proposals @neonbhai can you update your proposal with @s77rt feedback?

melvin-bot[bot] commented 3 months ago

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

wildan-m commented 3 months ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Group Chat custom avatar not saved when navigating back to invite members page

What is the root cause of that problem?

The screen remounts every time we navigate, causing the fileRef to be re-initialized upon returning.

What changes do you think we should make in order to solve the problem?

We can follow receipt flow to keep the avatar image persist by re-reading stored uri.

In src/pages/NewChatConfirmPage.tsx change fileRef to state, add avatarFile as createGroup dependency and add useEffect to re-read the stored file when re-mounts.

   const [avatarFile, setAvatarFile] = useState<File | CustomRNImageManipulatorResult | undefined>();    
 ..............

   useEffect(() => {
        if (!stashedLocalAvatarImage) {
            return;
        }

        const onSuccess = (file: File) => {
            setAvatarFile(file)
        };

        const onFailure = () => {
            setAvatarFile(undefined);
            Report.setGroupDraft({avatarUri: null, avatarFileName: null, avatarFileType: null});
        };
        FileUtils.readFileAsync(stashedLocalAvatarImage.toString(), newGroupDraft?.avatarFileName ?? '', onSuccess, onFailure, newGroupDraft?.avatarFileType ?? '');

    }, []);

Branch to test

What alternative solutions did you explore? (Optional)

We can move fileRef to a context to make it persist while navigate.

Create src/hooks/useFileRef.tsx

useFileRef.tsx ``` import React, { createContext, useContext, useRef, ReactNode } from 'react'; import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types'; // Define the type for the context type FileRefContextType = React.MutableRefObject | null; // Create the context const FileRefContext = createContext(null); // Custom hook to access the context const useFileRef = (): FileRefContextType => useContext(FileRefContext); // Define the type for the provider props type FileRefProviderProps = { children: ReactNode; }; // Provider component to manage the fileRef value const FileRefProvider = ({ children }: FileRefProviderProps) => { const fileRef = useRef(null); return ( {children} ); }; export { FileRefProvider, useFileRef } ```

Wrap RHP stack navigator with FileRefProvider

            <View style={styles.RHPNavigatorContainer(isSmallScreenWidth)}>
                <FileRefProvider>
                    <Stack.Navigator
 .....

fileRef in NewChatConfirmPage will use useFileRef

function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmPageProps) {
    const optimisticReportID = useRef<string>(ReportUtils.generateReportID());
    const fileRef = useFileRef();

Clean up

    const createGroup = useCallback(() => {
        if (!newGroupDraft) {
            return;
        }

        const logins: string[] = (newGroupDraft.participants ?? []).map((participant) => participant.login);
        Report.navigateToAndOpenReport(logins, true, newGroupDraft.reportName ?? '', newGroupDraft.avatarUri ?? '', fileRef &&fileRef.current, optimisticReportID.current, true);
        if (fileRef) {
            fileRef.current = undefined;
        }

Branch to test.

s77rt commented 3 months ago

@wildan-m Thanks for the proposal. Your RCA makes sense but the solution is over-engineered. We already have this flow working well with receipts. Let's follow the same approach.

wildan-m commented 3 months ago

@s77rt receipt has different case, perform back navigation from image preview will force the user to re-upload the scanned receipt, but group chat will expect we re-visit the image preview page without re-uploading the image.

s77rt commented 3 months ago

@wildan-m If you start the money request process from the FAB you can go back to the participants page

wildan-m commented 3 months ago

@s77rt thanks for the hints. I've updated my propsal.

Change log: Move prev solution to alternative, add new main solution that mimic receipt upload behavior.

s77rt commented 3 months ago

@wildan-m Thanks for looking into this. The solution looks good to me 👍.

🎀 👀 🎀 C+ reviewed Link to proposal

melvin-bot[bot] commented 3 months ago

Triggered auto assignment to @MonilBhavsar, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

wildan-m commented 3 months ago

@MonilBhavsar, do we need to consider anything else before we proceed?

MonilBhavsar commented 3 months ago

No thanks! looks good to me. Thanks for keeping it consistent with receipt scan flow

melvin-bot[bot] commented 3 months ago

📣 @s77rt 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link Upwork job

melvin-bot[bot] commented 3 months ago

📣 @wildan-m 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻 Keep in mind: Code of Conduct | Contributing 📖

wildan-m commented 3 months ago

@s77rt The PR is ready for review.

melvin-bot[bot] commented 2 months ago

Reviewing label has been removed, please complete the "BugZero Checklist".

melvin-bot[bot] commented 2 months ago

The solution for this issue has been :rocket: deployed to production :rocket: in version 9.0.0-9 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-06-28. :confetti_ball:

For reference, here are some details about the assignees on this issue:

melvin-bot[bot] commented 2 months ago

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

s77rt commented 2 months ago

Regression Test Proposal

  1. Click FAB > Start chat
  2. Select multiple users (group) and press Next
  3. Upload a group avatar
  4. Go back
  5. Click Next
  6. Click Start group
  7. Verify that the group is created and the custom avatar is used
marcaaron commented 2 months ago

LGTM

adelekennedy commented 2 months ago

Payouts due:

adelekennedy commented 2 months ago

https://github.com/Expensify/Expensify/issues/409492