Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

293 unlock new designs for shopify gate #294

Merged
merged 9 commits into from
Apr 9, 2024

Conversation

sebpalluel
Copy link
Contributor

@sebpalluel sebpalluel commented Apr 9, 2024

Type

enhancement, documentation


Description

  • Refactored Shopify feature pages to use new components (OffKeyAuth, OffKeyGate, OffKeyHeader, etc.) for better structure and functionality.
  • Implemented OffKeyLayout for consistent layout management across Shopify feature pages.
  • Added OffKeyProfile component for managing user profiles in connected state.
  • Introduced OffKeyGate component for managing gate states (unlocked, unlocking, used, locked).
  • Added localization support for new components and states.

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

    ✨ (shopify): add OffKeyInfo component with stories and types for state management
    🌐 (i18n): add localization support for OffKeyInfo states (unlocked, unlocking, used, locked)
    … consistency
    
    ✨ feat(shopify): add OffKeyHeader and OffKeyHeaderConnected components for enhanced UI
    📝 docs(shopify): update storybook examples to reflect new component structure and hooks usage
    
    ✨ (OffKeyHowToGet.stories.tsx, OffKeyHowToGet.tsx): add OffKeyHowToGet component and story for Shopify unlock feature
    ✨ (OffKeyInfo.stories.tsx, OffKeyInfo.tsx): add skeleton loader to OffKeyInfo and update stories
    ✨ (OffKeyProfile.stories.tsx): add stories for OffKeyProfile component with different user states
    
    ✨ (OffKeyProfile.tsx, examples.tsx, types.ts): add OffKeyProfile component, examples, and new types for Shopify feature
    🌐 (en.json): add translations for OffKeyProfile component in Shopify feature
    … to improve test accuracy
    
    ✨ (OffKeyAuth & OffKeyAuth.stories.tsx): add OffKeyAuth component and stories for enhanced wallet authentication flow
    
    ✨ (OffKeyAuthSignIn.tsx, examples.tsx): add OffKeyAuth components for Shopify unlock feature
    🚚 (OffKeyHeaderNotConnected.tsx): remove unused OffKeyHeaderNotConnected component
    📝 (en.json): update localization messages for OffKeyAuth feature
    ♻️ (OffKeyHeader.tsx): refactor OffKeyHeader to support optional profile and className props
    …er code
    
    ♻️ (OffKeyAuth/examples.tsx): replace Card with div for simpler structure
    ✨ (OffKeyGate): add new OffKeyGate component for gate state management
    📝 (OffKeyGate/examples.tsx): add examples for OffKeyGate component usage
    ♻️ (OffKeyHeader.tsx): adjust padding and separator margin for better layout
    🔧 (OffKeyHeaderConnected.stories.tsx): streamline decorators by removing unnecessary ones
    
    ✨ (OffKeyInfo.stories.tsx, OffKeyInfo.tsx): Add className prop to OffKeyInfo for styling flexibility
    ♻️ (OffKeyInfo.stories.tsx): Rename OffKeySkeleton to OffKeyInfoSkeleton for consistency
    ✨ (OffKeyProfile.tsx): Update Button styling for better UI consistency and add isIconOnly prop
    ✨ (getGateStateForAddress.ts): Implement getGateStateForAddress action for gate state management
    🌐 (en.json): Add localization for OffKeyGate and OffKeyHeaderConnected components
    … management
    
    - Replace `ShopifyAuth` with `OffKeyAuth` to utilize new authentication mechanism.
    - Introduce `OffKeyHeader` and `OffKeyLayout` components for better structure and design consistency.
    - Implement internationalization support in authentication components to enhance user experience across different locales.
    - Refactor layout components to use `OffKeyLayout`, improving code readability and maintainability.
    - Adjust CSS for `OffKeyAuth` to improve UI alignment and spacing, ensuring a cohesive look and feel.
    - Update examples to demonstrate the usage of new `OffKey` components, providing clear guidance for developers.
    - Introduced `OffKeyHeaderConnected`, `OffKeyProfile`, and `OffKeyGate` components to enhance the Shopify integration by providing a more cohesive and feature-rich user interface.
    - Implemented internationalization support for the new components to ensure a seamless user experience across different locales.
    - Refactored the layout structure to accommodate the new header and gate components, improving the overall page architecture and readability.
    - Removed outdated `@profile/page.tsx` in favor of a more integrated approach within the new layout system.
    - Updated the `index.ts` exports to include the newly added components, making them available for use across the application.
    - Enhanced the English locale messages to include translations for the newly introduced components, ensuring clarity and accessibility for English-speaking users.
    …ion error
    
    ♻️ (OffKeyProfile.tsx): refactor signOutUserAction to handle errors with specific toast message
    ♻️ Refactor page.tsx to use OffKeyGateSignIn, enhancing UX
    📝 Update en.json with new localization for gate sign-in text
    💡 Add TODO comment in OffKeyProfile.tsx for future error handling improvement
    @sebpalluel sebpalluel linked an issue Apr 9, 2024 that may be closed by this pull request
    Copy link

    vercel bot commented Apr 9, 2024

    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 codiumai-pr-agent-free bot added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 9, 2024
    Copy link

    PR Description updated to latest commit (8d0a4d2)

    Copy link

    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 by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    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]

    -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]

    -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]

    -return walletInStorage && walletInStorage.length > 1 ? (
    -  <div className="flex justify-center space-x-2">
    -    ...
    -  </div>
    -) : (
    -  <Button
    -    ...
    -  </Button>
    +return (
    +  walletInStorage.length > 1 ? (
    +    <div className="flex justify-center space-x-2">
    +      ...
    +    </div>
    +  ) : (
    +    <Button
    +      ...
    +    </Button>
    +  )
     );
     
    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]

    -// @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]

    -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]

    -const mockWallet = createMock(walletApi, 'useWalletAuth');
    -mockWallet.mockReturnValue(walletAuthMocks);
    +// Example using decorators for Storybook
    +export const decorators = [
    +  (Story) => (
    +    <MockProvider mocks={[{ request: { query: GET_DATA }, result: { data: mockData } }]}>
    +      <Story />
    +    </MockProvider>
    +  ),
    +];
     
    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]

    +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]

    -{existingWallet ? (
    -  <OffKeyAuthSignIn
    -    {...{
    -      isConnecting,
    -      connectWalletMutation,
    -      walletInStorage,
    -      existingWallet,
    -    }}
    -  />
    -) : (
    -  <Button
    -    block
    -    onClick={() =>
    -      connectWalletMutation.mutateAsync({ isCreatingAccount: true })
    -    }
    -  >
    -    {t('create-new-account')}
    -  </Button>
    -)}
    +renderAuthComponent() {
    +  if (existingWallet) {
    +    return <OffKeyAuthSignIn
    +      isConnecting={isConnecting}
    +      connectWalletMutation={connectWalletMutation}
    +      walletInStorage={walletInStorage}
    +      existingWallet={existingWallet}
    +    />;
    +  } else {
    +    return <Button
    +      block
    +      onClick={() => connectWalletMutation.mutateAsync({ isCreatingAccount: true })}
    +    >
    +      {t('create-new-account')}
    +    </Button>;
    +  }
    +}
    +// 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]

    -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]

    -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]

    -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]

    -// 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]

     <Button
       block
       onClick={() =>
         connectWalletMutation.mutateAsync({ isCreatingAccount: true })
       }
    +  disabled={isConnecting}
     >
    -  {t('create-new-account')}
    +  {isConnecting ? <Spinner /> : t('create-new-account')}
     </Button>
     
    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]

    -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]

     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]

    -<OffKeyLayout header={header}>
    +<OffKeyLayout>
    +  {header}
       {children}
       {auth}
     </OffKeyLayout>
     

    ✨ 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 every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 4
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Unlock, new designs for shopify gate
    1 participant