OfflineHQ / marketplace

https://offline.live/
GNU General Public License v3.0
0 stars 0 forks source link

293 unlock new designs for shopify gate #294

Closed sebpalluel closed 7 months ago

sebpalluel commented 7 months ago

Type

enhancement, documentation


Description


Changes walkthrough

Relevant files
Enhancement
12 files
page.tsx
Refactor Auth Page to Use OffKeyAuth Component                     

apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/@auth/page.tsx
  • Refactored to use OffKeyAuth component with localization support.
  • Added NextIntlClientProvider for localized messages.
  • +20/-3   
    page.tsx
    Implement OffKeyHeader in Header Page                                       

    apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/@header/page.tsx - Implemented `OffKeyHeader` component for the header section.
    +12/-0   
    layout.tsx
    Use OffKeyLayout for Layout Management                                     

    apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/layout.tsx
  • Replaced ShopifyCard with OffKeyLayout for layout management.
  • Added support for rendering header component.
  • +17/-11 
    page.tsx
    Integrate OffKeyGateSignIn Component                                         

    apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/page.tsx - Introduced `OffKeyGateSignIn` component for sign-in functionality.
    +6/-11   
    page.tsx
    Implement Connected User Header with OffKeyProfile             

    apps/unlock/app/[locale]/shopify/[gateId]/[address]/@header/page.tsx
  • Utilized OffKeyHeaderConnected and OffKeyProfile for connected user
    header.
  • +32/-0   
    layout.tsx
    Use OffKeyLayout in Address-Specific Layout                           

    apps/unlock/app/[locale]/shopify/[gateId]/[address]/layout.tsx
  • Switched to OffKeyLayout for layout management in address-specific
    pages.
  • +6/-18   
    page.tsx
    Implement OffKeyGate Component for Gate State Management 

    apps/unlock/app/[locale]/shopify/[gateId]/[address]/page.tsx - Implemented `OffKeyGate` component to manage gate state.
    +30/-2   
    index.ts
    Export New Components for Shopify Feature                               

    libs/features/unlock/shopify/src/index.ts
  • Exported new components (OffKeyAuth, OffKeyGate, OffKeyGateSignIn,
    etc.) from the library.
  • +8/-0     
    OffKeyAuth.tsx
    Add OffKeyAuth Component for Wallet Authentication             

    libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuth.tsx - Added `OffKeyAuth` component for wallet authentication flow.
    +119/-0 
    OffKeyGate.tsx
    Introduce OffKeyGate Component                                                     

    libs/features/unlock/shopify/src/lib/OffKeyGate/OffKeyGate.tsx - Introduced `OffKeyGate` component for gate state management.
    +64/-0   
    OffKeyHeader.tsx
    Implement OffKeyHeader Component                                                 

    libs/features/unlock/shopify/src/lib/OffKeyHeader/OffKeyHeader.tsx - Implemented `OffKeyHeader` component for the header section.
    +32/-0   
    OffKeyProfile.tsx
    Add OffKeyProfile Component for User Profile Management   

    libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx - Added `OffKeyProfile` component for user profile management.
    +191/-0 
    Documentation
    1 files
    en.json
    Add Translations for New Shopify Feature Components           

    libs/next/i18n/src/messages/en.json
  • Added translations for new components (OffKeyAuth, OffKeyGate,
    OffKeyProfile, etc.).
  • +34/-0   

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    vercel[bot] commented 7 months ago

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    back-office ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2024 11:10am
    marketplace ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2024 11:10am
    unlock ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2024 11:10am
    codiumai-pr-agent-free[bot] commented 7 months ago

    PR Description updated to latest commit (https://github.com/OfflineHQ/marketplace/commit/8d0a4d254b4b9cdb5f7f8e1c889ac0885acd90b9)

    codiumai-pr-agent-free[bot] commented 7 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 4, due to the extensive changes across multiple files, including new components, refactoring, and localization support. The PR introduces significant enhancements and new features, requiring a thorough review of code quality, functionality, and integration with existing systems.
    🧪 Relevant tests No
    🔍 Possible issues Possible Bug: The use of `useEffect` hooks in `OffKeyProfile.tsx` without a dependency array might lead to unexpected behavior or infinite loops. Consider adding a dependency array to control the effect's execution.
    Code Duplication: Similar code patterns are observed in `OffKeyAuth.tsx` and `OffKeyProfile.tsx` for handling wallet connections. Consider abstracting common logic into reusable hooks or components to reduce duplication and improve maintainability.
    Localization Consistency: Ensure that all user-facing text is included in the localization files and properly utilized in the components. This includes error messages and dynamic content that might not be currently covered.
    Performance Concern: The extensive use of animations and dynamic content in components like `OffKeyGate.tsx` and `OffKeyHeaderConnected.tsx` might impact performance on lower-end devices. Consider optimizing animations and conditional rendering to improve the user experience across all devices.
    🔒 Security concerns No

    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    codiumai-pr-agent-free[bot] commented 7 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Use a more specific error type instead of any for error handling in mutations. ___ **Consider using a more specific error type in the onError callback of your mutations to
    improve error handling. Using any for the error type can make it difficult to handle
    errors properly since you lose type information. TypeScript provides a way to define
    custom error types or you can use existing error types that are more specific to the
    context of the error.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx [57-59]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-4b035f23e367c8645366640c5b6355e6bdd60a52f6a10b88ef9f4f93db8a16ebR57-R59) ```diff -onError: (error: any) => { +onError: (error: Error) => { // Handle connection error }, ```
    Avoid using console.log in production code for better code quality. ___ **It's a good practice to avoid direct console logging in production code, especially in
    success or error handlers of mutations. Consider using a more robust logging mechanism or
    remove the console logs if they were used for debugging purposes.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx [54-69]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-4b035f23e367c8645366640c5b6355e6bdd60a52f6a10b88ef9f4f93db8a16ebR54-R69) ```diff -console.log('connected to wallet'); -console.log('error connecting to dapp', error); +// Use a logging library or remove the console.log statements ```
    Use a ternary operator for conditional rendering to improve readability. ___ **To improve code readability and maintainability, consider using a ternary operator for
    conditional rendering based on walletInStorage.length > 1. This change would make the
    component's structure clearer and more concise.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuthSignIn.tsx [34-70]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-a7a38c4ba86bbda1719d0fc1a196c2a6324076a0f3036bf2acb6e8612e42f923R34-R70) ```diff -return walletInStorage && walletInStorage.length > 1 ? ( -
    - ... -
    -) : ( -
    Use className for consistency with React's conventions. ___ **Replace the class attribute with className to adhere to React's naming conventions.
    Additionally, remove the // @ts-expect-error comment if it's no longer necessary, ensuring
    TypeScript compatibility.** [libs/features/unlock/app-nav/src/lib/OffKeyLogo/OffKeyLogo.tsx [9]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-c320ce308703be0b25aa89d914609ae202e41b9dc8c00c0b2075c59eef9d0ad0R9-R9) ```diff -// @ts-expect-error -class={props.className} +className={props.className} ```
    Remove unused function parameters. ___ **Consider removing the unused container parameter from the play function in your Storybook
    stories to adhere to best practices and improve code readability.** [libs/features/unlock/shopify/src/lib/OffKeyGate/OffKeyGate.stories.tsx [35-36]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-54f8a03cadd7b355809e667b7bfe2e620e4d830e84c59d40c8d9c6bb628c743cR35-R36) ```diff -play: async ({ container }) => { +play: async () => { await screen.findAllByText(/Unlocked/i); }, ```
    Use decorators or parameters for mocking in Storybook. ___ **Instead of directly mocking the hooks using createMock, consider using a more integrated
    testing approach with Storybook by utilizing decorators or parameters to provide mock
    data. This approach can improve maintainability and separation of concerns.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/examples.tsx [36-38]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-073ecf024148eed78fbb8ff30bf2f628c971668ccac1c92296a29dbf19bb38e3R36-R38) ```diff -const mockWallet = createMock(walletApi, 'useWalletAuth'); -mockWallet.mockReturnValue(walletAuthMocks); +// Example using decorators for Storybook +export const decorators = [ + (Story) => ( + + + + ), +]; ```
    Maintainability
    Extract mutation functions into separate named functions for better maintainability. ___ **To improve code maintainability and readability, consider extracting the mutation
    functions (mutationFn, onSuccess, onError) into separate named functions outside of the
    component. This not only makes the component cleaner but also makes it easier to test
    these functions in isolation.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx [51-60]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-4b035f23e367c8645366640c5b6355e6bdd60a52f6a10b88ef9f4f93db8a16ebR51-R60) ```diff +const handleConnectWallet = (newWallet: string) => connect(newWallet); +const onConnectWalletSuccess = () => { + console.log('connected to wallet'); + // Handle successful connection +}; +const onConnectWalletError = (error: Error) => { + // Handle connection error +}; const connectWalletMutation = useMutation({ - mutationFn: (newWallet: string) => connect(newWallet), - onSuccess: () => { - console.log('connected to wallet'); - // Handle successful connection - }, - onError: (error: any) => { - // Handle connection error - }, + mutationFn: handleConnectWallet, + onSuccess: onConnectWalletSuccess, + onError: onConnectWalletError, }); ```
    Use ternary operator or separate function for conditional rendering for clarity. ___ **For better code readability and maintainability, consider using a ternary operator or a
    separate rendering function for conditional rendering instead of using the logical AND
    (&&) operator. This can make the code easier to understand, especially for more complex
    conditional renderings.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuth.tsx [51-69]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-dd427743a002e3dad8c75f54ed95a9092983490a56a5fc378a0e3ec2a5d6bdf6R51-R69) ```diff -{existingWallet ? ( - -) : ( - -)} +renderAuthComponent() { + if (existingWallet) { + return ; + } else { + return ; + } +} +// Usage: {this.renderAuthComponent()} ```
    Improve variable naming for clarity. ___ **Consider using a more descriptive variable name for t to improve code readability. For
    example, translate or tFunction would make it clearer that this variable is used for
    internationalization.** [libs/features/unlock/shopify/src/lib/OffKeyInfo/OffKeyInfo.tsx [40]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-afda0c3e7456144fe461301c4114afbbcca1583d473b3be76f8fc49bf2fd9ecbR40-R40) ```diff -const t = useTranslations('Shopify.OffKeyInfo'); +const translate = useTranslations('Shopify.OffKeyInfo'); ```
    Consolidate state mappings into a single mapping for simplicity. ___ **Instead of hardcoding the translations keys and creating separate state mappings for
    subtitles and main text, consider creating a single mapping that includes all the
    necessary information for each state. This approach reduces redundancy and simplifies the
    component's structure.** [libs/features/unlock/shopify/src/lib/OffKeyGate/OffKeyGate.tsx [29-39]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-b04caa7332ebff9c207f545552e87b6297915d203992f9e5bfe4f6569ecd2ed8R29-R39) ```diff -const stateToSubtitle = { - [OffKeyState.Unlocked]: t('unlocked-subtitle'), - ... -}; -const stateToMainText = { - [OffKeyState.Unlocked]: t('unlocked-text'), +const stateToContent = { + [OffKeyState.Unlocked]: { subtitle: t('unlocked-subtitle'), mainText: t('unlocked-text') }, ... }; ```
    Define mock functions externally for better modularity. ___ **To improve the reusability and readability of your mock functions, consider defining them
    outside of the authMocks function or in a separate utility file. This change can make your
    tests more modular and easier to maintain.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/examples.tsx [29-31]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-a989bfef297ab964b9c8680402fa4386ede798d35806e0886f124aefe5ca466fR29-R31) ```diff -const mockWallet = createMock(walletApi, 'useWalletAuth'); -mockWallet.mockReturnValue(walletAuthMocks); +// In a separate utility file or outside the function +export const mockWalletAuth = createMock(walletApi, 'useWalletAuth'); +mockWalletAuth.mockReturnValue(walletAuthMocks); ```
    Implement or remove TODO comments to avoid technical debt. ___ **Implement the actual logic for getGateStateForAddress or remove the TODO comment if the
    function is not meant to be expanded. Leaving TODO comments in production code can lead to
    confusion and technical debt.** [libs/features/unlock/shopify/src/lib/actions/getGateStateForAddress.ts [13-21]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-2ae7ec5f54c9a1e6b79d3b98ed85adfdc3ea0376c7a05dab3885ec0de3c072f5R13-R21) ```diff -// TODO implement -// return __awaiter(this, void 0, void 0, function* () { -// return { -// status: 'locked', -// gateId, -// address, -// }; -// }); -return OffKeyState.Locked; +// Implemented version (example) +return fetchGateState(gateId, address); ```
    Enhancement
    Improve user feedback by handling the isConnecting state in the UI. ___ **To enhance the user experience and provide feedback during the connection process,
    consider handling the isConnecting state more explicitly in the UI. For instance, you can
    disable the connect button and show a loading indicator when isConnecting is true.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuth.tsx [61-68]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-dd427743a002e3dad8c75f54ed95a9092983490a56a5fc378a0e3ec2a5d6bdf6R61-R68) ```diff ```
    Pass state mappings as props for flexibility and maintainability. ___ **To ensure that the component is more flexible and easier to maintain, consider passing
    stateToBorderColor, stateToKeyIcon, stateToStatusBackground, and other similar mappings as
    props. This change would make the component more reusable and easier to test.** [libs/features/unlock/shopify/src/lib/OffKeyInfo/OffKeyInfo.tsx [14-31]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-afda0c3e7456144fe461301c4114afbbcca1583d473b3be76f8fc49bf2fd9ecbR14-R31) ```diff -const stateToBorderColor = { - [OffKeyState.Unlocked]: 'border-success-border', - ... -}; +export function OffKeyInfo({ state, offKeyName, className, stateMappings }: OffKeyInfoProps & { stateMappings: StateMappings }) { ```
    Add a description to the NotConnected story for better context. ___ **Consider adding a description to the NotConnected story to provide more context to other
    developers or designers who might use this story. This can be done by adding a description
    field under parameters within the story definition. This helps in understanding the
    purpose of the story and the specific state it represents without needing to dive into the
    code.** [libs/features/unlock/shopify/src/lib/OffKeyHeader/OffKeyHeader.stories.tsx [15-18]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-d8f855fdaaf4a2b04711cd8cf9c209e9c8c5d5696f37a42b5304fafd948c7b5cR15-R18) ```diff export const NotConnected: Story = { args: { title: 'Locked with the Dummy Brand OffKey', }, + parameters: { + docs: { + description: { + story: 'Displays the OffKeyHeader in a not connected state, indicating it is locked with the Dummy Brand OffKey.', + }, + }, + }, }; ```
    Possible issue
    Ensure props are utilized or remove unnecessary props. ___ **The header prop is being passed to OffKeyLayout but not utilized within it. Ensure that
    the header prop is correctly implemented inside OffKeyLayout or reconsider its necessity
    if it's not being used.** [apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/layout.tsx [24-26]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-300c9bf8ed78b5df256207749beeb349d0c908ad0c736d2ffa6a5f20e3c9090dR24-R26) ```diff - + + {header} {children} {auth} ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.