Skip to content

Commit

Permalink
fix: sync onboarding request and form hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-van-woerkens committed Dec 5, 2023
1 parent aa7e0e2 commit 135adec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fileignoreconfig:
checksum: 390c88e78b3e8bd3153e028403a3ffea2b5da636eeab22c307788cbddb86e096
- filename: src/components/users/toggle-account-modal.tsx
checksum: 2d0bd58b461814a6d2d934d96441ed7962a74f2d184e2581b38b4990562dde70
- filename: src/hooks/use-onboarding.ts
checksum: 5a4e696e13c7b9674979b192acb1e73b55694b93e54d54e805b74ad3a288dc40
- filename: src/services/disablers/ovh.ts
checksum: 390c9e51cf01b5db14a4af94a4182c3d55ccddeb7905462b21b0a5f23b8d24e9
- filename: src/services/enablers/ovh.ts
Expand Down
8 changes: 3 additions & 5 deletions src/components/common/wizard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react"
import { useState } from "react"

import Stepper from "./stepper"

Expand All @@ -17,13 +17,10 @@ const Wizard = ({
}) => {
const [isValidStep, setValidStep] = useState(false)
const [activeStepIndex, setActiveStepIndex] = useState(0)
const [fields, setFields] = useState<OnboardingData | undefined>(data)

const { component: Step } = steps[activeStepIndex]
const isLastStep = activeStepIndex === steps.length - 1

useEffect(() => setFields(data), [data])

const PreviousButton = () => (
<button
className="primary flex leading-4"
Expand Down Expand Up @@ -58,7 +55,8 @@ const Wizard = ({
className="primary flex leading-4"
onClick={(e) => {
e.preventDefault()
onComplete(fields)
// onComplete(fields)
onComplete(data)
}}
>
Terminer
Expand Down
5 changes: 2 additions & 3 deletions src/components/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useEffect, useMemo, useState } from "react"
import statusOk from "@/utils/status-ok"
import Alert from "@/components/common/alert"
import Wizard from "@/components/common/wizard"
import useOnboarding from "@/hooks/use-onboarding"
import graphQLFetcher from "@/utils/graphql-fetcher"
import UserInfo from "@/components/onboarding/steps/user-info"
import useOnboarding, { fallbackData } from "@/hooks/use-onboarding"
import GithubServices from "@/components/onboarding/steps/github-services"
import DefaultServices from "@/components/onboarding/steps/default-services"
import ServicesAccountsStatuses from "@/components/onboarding/steps/services-accounts-statuses"
Expand All @@ -16,7 +16,7 @@ import {
} from "@/queries/index"

const Onboarding = () => {
const { data, request, id, mutate: mutateOnboarding } = useOnboarding()
const { data, request, id } = useOnboarding()

const [status, setStatus] = useState<
"create" | "review" | "reviewed" | "create_success" | "review_success"
Expand Down Expand Up @@ -64,7 +64,6 @@ const Onboarding = () => {
} else if (status === "create") {
handleCreationSubmit()
}
await mutateOnboarding(fallbackData)
}

useEffect(() => {
Expand Down
13 changes: 7 additions & 6 deletions src/hooks/use-onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import useSWR from "swr"

import useOnboardingRequest from "./use-onboarding-request"

export const fallbackData = {
const defaultData = {
email: "",
message: "",
lastName: "",
Expand All @@ -19,15 +19,16 @@ export const fallbackData = {
const useOnboarding = () => {
const { request, id } = useOnboardingRequest()

const key = id ? `onboarding-${id}` : "onboarding"
const fallbackData = id ? request?.data : defaultData

const {
data,
mutate,
}: { data?: OnboardingData; mutate: KeyedMutator<unknown> } = useSWR(
"onboarding",
}: { data?: OnboardingData; mutate: KeyedMutator<OnboardingData> } = useSWR(
key,
null,
{
fallbackData: request?.data || fallbackData,
}
{ fallbackData }
)

return { data, mutate, request, id }
Expand Down

0 comments on commit 135adec

Please sign in to comment.