Skip to content

Commit

Permalink
Merge branch 'develop' into fix/style
Browse files Browse the repository at this point in the history
  • Loading branch information
neverm25 committed Sep 6, 2024
2 parents f7d785e + 2536227 commit 824d7ec
Show file tree
Hide file tree
Showing 129 changed files with 24,730 additions and 26,546 deletions.
62 changes: 31 additions & 31 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
name: Continuous Integration
# name: Continuous Integration

on:
pull_request:
push:
# need a personal access token (PAT) instead of GITHUB_TOKEN
# branches:
# - main
# - staging
# - develop
# on:
# pull_request:
# push:
# # need a personal access token (PAT) instead of GITHUB_TOKEN
# # branches:
# # - main
# # - staging
# # - develop

jobs:
prettier:
runs-on: ubuntu-latest
# jobs:
# prettier:
# runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }} # Use GitHub token for authentication
ref: ${{ github.head_ref }}
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# token: ${{ secrets.GITHUB_TOKEN }} # Use GitHub token for authentication
# ref: ${{ github.head_ref }}

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
# - name: Use Node.js
# uses: actions/setup-node@v2
# with:
# node-version: '18'

- name: Install Dependencies
run: yarn install --frozen-lockfile
# - name: Install Dependencies
# run: yarn install --frozen-lockfile

- name: Prettify code
uses: creyD/[email protected]
with:
# This part is also where you can pass other options, for example:
prettier_options: --write .
# Use GitHub token for authentication
github_token: ${{ secrets.GITHUB_TOKEN }}
# - name: Prettify code
# uses: creyD/[email protected]
# with:
# # This part is also where you can pass other options, for example:
# prettier_options: --write .
# # Use GitHub token for authentication
# github_token: ${{ secrets.GITHUB_TOKEN }}
192 changes: 192 additions & 0 deletions docs/create_new_flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# SOP: Creating New Visual Flows in peanut-ui

## Purpose

This document outlines the steps for creating a new visual flow with multiple screens in the peanut-ui. The goal is to ensure consistency in implementing new flows, including parent components, multiple views, navigation logic, and screen state management.

---

## Folder Structure

Each new flow consists of a parent component, a folder for view components, a constants file to manage the flow, and TypeScript definitions for props and screen types.

The general structure:

```
/components
/[FlowName]
/Views
- Initial.view.tsx
- Success.view.tsx
- [FlowName].tsx
- [FlowName].consts.ts
- index.ts
```

---

## Step-by-Step Process

### 1. **Create the Folder Structure**

Create a new folder inside the `/components` directory for the new flow. This folder should mirror the structure shown in the existing `Create` flow, with the following subdirectories and files:

- **Views Folder**: This will contain the individual screens of the flow.
- **Parent Component**: This will manage the navigation between screens and hold the flow's state.
- **Constants File**: This will define the screens, flow, and screen mapping.

For example, to create a new flow called `NewFlow`:

```
/components
/NewFlow
/Views
- Initial.view.tsx
- Success.view.tsx
- ...
- NewFlow.tsx
- NewFlow.consts.ts
- index.ts
```

### 2. **Define Constants**

In the `[FlowName].consts.ts` file, define the screen flow, state, and mappings similar to how it is done in the `Create.consts.ts` file.

Example for `NewFlow.consts.ts`:

```ts
import * as views from './Views'

export type NewFlowScreens = 'INITIAL' | 'SUCCESS'

export interface INewFlowScreenState {
screen: NewFlowScreens
idx: number
}

export const INIT_NEW_FLOW_VIEW_STATE: INewFlowScreenState = {
screen: 'INITIAL',
idx: 0,
}

export const NEW_FLOW_SCREEN_FLOW: NewFlowScreens[] = ['INITIAL', 'SUCCESS']

export const NEW_FLOW_SCREEN_MAP: { [key in NewFlowScreens]: { comp: React.FC<any> } } = {
INITIAL: { comp: views.InitialView },
SUCCESS: { comp: views.SuccessView },
}

export interface INewFlowScreenProps {
onNext: () => void
onPrev: () => void
link: string
setLink: (value: string) => void
// Add other props as needed
}
```

### 3. **Create Views**

Create the individual screens (views) for your new flow inside the `/Views` folder. Each screen should be a `.tsx` file and should receive the props necessary for navigation and state updates.

For example, `Initial.view.tsx` might look like:

```tsx
import React from 'react'
import * as _consts from '../NewFlow.consts'
export const InitialView = ({ onNext, link, setLink }: _consts.INewFlowScreenProps) => {
return (
<div>
<h1>Initial View</h1>
{/* Add UI elements for the initial screen */}
<button onClick={onNext}>Next</button>
</div>
)
}
```

Ensure each view component corresponds with the screen flow defined in the constants file.

### 4. **Create Parent Component**

Create the parent component that will manage the flow between screens. This component will hold the state and navigation logic (next, previous steps) and pass relevant props to the screen components.

Example for `NewFlow.tsx`:

```tsx
'use client'

import { createElement, useEffect, useState } from 'react'
import * as _consts from './NewFlow.consts'
import { useAccount } from 'wagmi'

export const NewFlowComponent = () => {
const [step, setStep] = useState<_consts.INewFlowScreenState>(_consts.INIT_NEW_FLOW_VIEW_STATE)
const [link, setLink] = useState<string>('')

const handleOnNext = () => {
if (step.idx === _consts.NEW_FLOW_SCREEN_FLOW.length - 1) return
const newIdx = step.idx + 1
setStep({
screen: _consts.NEW_FLOW_SCREEN_FLOW[newIdx],
idx: newIdx,
})
}

const handleOnPrev = () => {
if (step.idx === 0) return
const newIdx = step.idx - 1
setStep({
screen: _consts.NEW_FLOW_SCREEN_FLOW[newIdx],
idx: newIdx,
})
}

return (
<div className="card">
{createElement(_consts.NEW_FLOW_SCREEN_MAP[step.screen].comp, {
onNext: handleOnNext,
onPrev: handleOnPrev,
link,
setLink,
})}
</div>
)
}
```

### 5. **Index File**

The `index.ts` file should export the parent component of the new flow to make it available for import.

```ts
export { NewFlowComponent } from './NewFlow'
```

### 6. **Test the Flow**

1. **Import the Component**: Import the new flow component in your application where necessary.

```ts
import { NewFlowComponent } from '@/components/NewFlow'
```

2. **Run the App**: Ensure that each screen is functioning properly and that the navigation between steps is correct.
3. **Test Edge Cases**: Verify behavior at the beginning and end of the flow, such as disabling the "Previous" button on the first screen and the "Next" button on the last screen.

---

## Best Practices

- **Consistent Naming**: Follow the established naming conventions for files, types, and states.
- **Modular Views**: Keep each view screen modular, focusing only on the specific UI and functionality of that screen.
- **Prop Validation**: Ensure all props passed to screens are typed correctly using TypeScript interfaces.
- **Component Reusability**: Consider reusability of components across different flows when applicable.

---

## Troubleshooting

- **Missing Props**: If a component fails to render, check if all required props are being passed correctly from the parent component.
- **Navigation Issues**: Ensure that the `CREATE_SCREEN_FLOW` or equivalent flow is correctly updated in the constants file and that the index manipulation logic works as intended.
91 changes: 41 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,80 @@
"lint": "next lint"
},
"dependencies": {
"@calcom/embed-react": "^1.3.0",
"@chakra-ui/color-mode": "^2.1.11",
"@calcom/embed-react": "^1.5.0",
"@chakra-ui/color-mode": "^2.2.0",
"@chakra-ui/react": "^2.8.2",
"@dicebear/collection": "^9.1.0",
"@dicebear/core": "^9.1.0",
"@headlessui/react": "^1.7.17",
"@headlessui/tailwindcss": "^0.2.0",
"@heroicons/react": "^2.1.1",
"@hotjar/browser": "^1.0.9",
"@n8tb1t/use-scroll-position": "^2.0.3",
"@safe-global/safe-apps-sdk": "^9.0.0",
"@dicebear/collection": "^9.2.1",
"@dicebear/core": "^9.2.1",
"@headlessui/react": "^1.7.19",
"@headlessui/tailwindcss": "^0.2.1",
"@safe-global/safe-apps-sdk": "^9.1.0",
"@sentry/nextjs": "^8.26.0",
"@squirrel-labs/peanut-sdk": "^0.4.61",
"@tanstack/react-query": "^5.29.2",
"@typeform/embed-react": "^3.17.0",
"@vercel/analytics": "^1.1.2",
"@squirrel-labs/peanut-sdk": "^0.4.67",
"@tanstack/react-query": "^5.52.1",
"@typeform/embed-react": "^3.20.0",
"@vercel/analytics": "^1.3.1",
"@vercel/og": "^0.6.2",
"@web3inbox/core": "^1.2.0",
"@web3inbox/react": "^1.2.0",
"@web3modal/siwe": "^5.0.1",
"@web3modal/wagmi": "^5.0.1",
"autoprefixer": "^10.4.14",
"awesome-phonenumber": "^6.8.0",
"axios": "^1.4.0",
"@web3modal/wagmi": "^5.1.2",
"autoprefixer": "^10.4.20",
"axios": "^1.7.5",
"chakra-ui-steps": "^2.1.0",
"country-list": "^2.3.0",
"encoding": "^0.1.13",
"eslint-config-next": "^14.1.1",
"eslint-config-next": "^14.2.6",
"ethers": "5.7.2",
"frames.js": "^0.15.2",
"fs-extra": "^11.2.0",
"i18n-iso-countries": "^7.11.2",
"i18n-iso-countries": "^7.11.3",
"install": "^0.13.0",
"jotai": "^2.2.2",
"libphonenumber-js": "^1.11.2",
"logrocket": "^8.1.0",
"libphonenumber-js": "^1.11.7",
"logrocket": "^8.1.2",
"lokijs": "^1.5.12",
"lottie-react": "^2.4.0",
"multicoin-address-validator": "^0.5.18",
"next": "^14.2.3",
"multicoin-address-validator": "^0.5.21",
"next": "^14.2.6",
"node-fetch": "^3.3.2",
"pino-pretty": "^10.0.1",
"pino-pretty": "^10.3.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react": "^18.3.1",
"react-csv": "^2.2.2",
"react-device-detect": "^2.2.3",
"react-dom": "^18.2.0",
"react-fast-marquee": "^1.6.0",
"react-dom": "^18.3.1",
"react-fast-marquee": "^1.6.5",
"react-ga4": "^2.1.0",
"react-google-recaptcha": "^3.1.0",
"react-hook-form": "^7.42.1",
"react-hook-form": "^7.53.0",
"react-lottie": "^1.2.4",
"react-qr-code": "^2.0.11",
"react-tooltip": "^5.21.5",
"react-qr-code": "^2.0.15",
"react-tooltip": "^5.28.0",
"sharp": "^0.32.6",
"siwe": "^2.3.2",
"tailwind-merge": "^1.12.0",
"tailwind-merge": "^1.14.0",
"tailwind-scrollbar": "^3.1.0",
"tap": "^18.4.2",
"tap": "^18.8.0",
"three": "^0.157.0",
"uuid": "^10.0.0",
"validator": "^13.12.0",
"viem": "^2.10.5",
"viem": "^2.20.0",
"wagmi": "2.8.6",
"web3": "^1.7.0"
"web3": "^1.10.4"
},
"devDependencies": {
"@types/country-list": "^2.1.4",
"@types/fs-extra": "^11.0.4",
"@types/multicoin-address-validator": "^0.5.3",
"@types/node": "20.4.2",
"@types/react": "^18.2.22",
"@types/react-csv": "^1.1.3",
"@types/react-dom": "^18.2.7",
"@types/react": "^18.3.4",
"@types/react-csv": "^1.1.10",
"@types/react-dom": "^18.3.0",
"@types/react-google-recaptcha": "^2.1.9",
"@types/react-lottie": "^1.2.10",
"@types/three": "^0.157.0",
"@types/three": "^0.157.2",
"@types/uuid": "^9.0.8",
"@types/validator": "^13.11.10",
"postcss": "^8",
"prettier": "^3.0.2",
"prettier-plugin-tailwindcss": "^0.5.3",
"tailwindcss": "^3.4.1",
"typescript": "^5"
"@types/validator": "^13.12.0",
"postcss": "^8.4.41",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.5.14",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4"
}
}
Loading

0 comments on commit 824d7ec

Please sign in to comment.