-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from UgnisSoftware/UGN-422
Back button navigation
- Loading branch information
Showing
16 changed files
with
163 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import { Button, ModalFooter } from "@chakra-ui/react" | ||
import { Button, ModalFooter, useStyleConfig } from "@chakra-ui/react" | ||
import { themeOverrides } from "../theme" | ||
|
||
type ContinueButtonProps = { | ||
onContinue: (val: any) => void | ||
onBack?: () => void | ||
title: string | ||
backTitle?: string | ||
isLoading?: boolean | ||
} | ||
|
||
export const ContinueButton = ({ onContinue, title, isLoading }: ContinueButtonProps) => ( | ||
<ModalFooter> | ||
<Button size="lg" w="21rem" onClick={onContinue} isLoading={isLoading}> | ||
{title} | ||
</Button> | ||
</ModalFooter> | ||
) | ||
export const ContinueButton = ({ onContinue, onBack, title, backTitle, isLoading }: ContinueButtonProps) => { | ||
const styles = useStyleConfig("Modal") as (typeof themeOverrides)["components"]["Modal"]["baseStyle"] | ||
const nextButtonMobileWidth = onBack ? "8rem" : "100%" | ||
return ( | ||
<ModalFooter> | ||
{onBack && ( | ||
<Button size="md" sx={styles.backButton} onClick={onBack} isLoading={isLoading} variant="link"> | ||
{backTitle} | ||
</Button> | ||
)} | ||
<Button | ||
size="lg" | ||
w={{ base: nextButtonMobileWidth, md: "21rem" }} | ||
sx={styles.continueButton} | ||
onClick={onContinue} | ||
isLoading={isLoading} | ||
> | ||
{title} | ||
</Button> | ||
</ModalFooter> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
import { UploadFlow } from "./UploadFlow" | ||
import { StepState, StepType, UploadFlow } from "./UploadFlow" | ||
import { ModalHeader } from "@chakra-ui/react" | ||
import { useSteps, Step, Steps as Stepper } from "chakra-ui-steps" | ||
import { CgCheck } from "react-icons/cg" | ||
|
||
import { useRsi } from "../hooks/useRsi" | ||
import { useRsiInitialStep } from "../hooks/useRsiInitialStep" | ||
import { useRef, useState } from "react" | ||
import { steps, stepTypeToStepIndex, stepIndexToStepType } from "../utils/steps" | ||
|
||
const CheckIcon = ({ color }: { color: string }) => <CgCheck size="2.25rem" color={color} /> | ||
|
||
export const Steps = () => { | ||
const { initialStepState, translations } = useRsi() | ||
const { initialStepState, translations, isNavigationEnabled } = useRsi() | ||
|
||
const { steps, initialStep } = useRsiInitialStep(initialStepState?.type) | ||
const initialStep = stepTypeToStepIndex(initialStepState?.type) | ||
|
||
const { nextStep, activeStep } = useSteps({ | ||
const { nextStep, activeStep, setStep } = useSteps({ | ||
initialStep, | ||
}) | ||
|
||
const [state, setState] = useState<StepState>(initialStepState || { type: StepType.upload }) | ||
|
||
const history = useRef<StepState[]>([]) | ||
|
||
const onClickStep = (stepIndex: number) => { | ||
const type = stepIndexToStepType(stepIndex) | ||
const historyIdx = history.current.findIndex((v) => v.type === type) | ||
if (historyIdx === -1) return | ||
const nextHistory = history.current.slice(0, historyIdx + 1) | ||
history.current = nextHistory | ||
setState(nextHistory[nextHistory.length - 1]) | ||
setStep(stepIndex) | ||
} | ||
|
||
const onBack = () => { | ||
onClickStep(Math.max(activeStep - 1, 0)) | ||
} | ||
|
||
const onNext = (v: StepState) => { | ||
history.current.push(state) | ||
setState(v) | ||
v.type !== StepType.selectSheet && nextStep() | ||
} | ||
|
||
return ( | ||
<> | ||
<ModalHeader display={["none", "none", "block"]}> | ||
<Stepper activeStep={activeStep} checkIcon={CheckIcon}> | ||
<Stepper | ||
activeStep={activeStep} | ||
checkIcon={CheckIcon} | ||
onClickStep={isNavigationEnabled ? onClickStep : undefined} | ||
responsive={false} | ||
> | ||
{steps.map((key) => ( | ||
<Step label={translations[key].title} key={key} /> | ||
))} | ||
</Stepper> | ||
</ModalHeader> | ||
<UploadFlow nextStep={nextStep} /> | ||
<UploadFlow state={state} onNext={onNext} onBack={isNavigationEnabled ? onBack : undefined} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.