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

feat(form-v2/design-2): logo radio buttons and form color theme selection #4271

Merged
merged 26 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f2bbef5
feat: added design drawer, allow user to edit estimated completion ti…
justynoh Jul 13, 2022
99bb8d1
refactor: some code refactoring, updated FormBuilder to reuse code fr…
justynoh Jul 13, 2022
b5bca86
refactor: updated builder start page view and public start page view …
justynoh Jul 14, 2022
69659b3
chore: added fake SPCP id in builder.
justynoh Jul 14, 2022
a3ff27e
Merge branch 'form-v2/develop' of https://github.com/opengovsg/FormSG…
justynoh Jul 14, 2022
bc04312
Merge remote-tracking branch 'origin/form-v2/develop' into form-v2/fe…
justynoh Jul 19, 2022
4cb7644
chore: resolve merge conflicts with v2/develop
justynoh Jul 19, 2022
74a1e2e
chore: updated MiniHeader tests
justynoh Jul 19, 2022
6781752
fix: update design padding for empty form builder placeholder.
justynoh Jul 19, 2022
81921cb
fix: update design padding for empty form builder placeholder... again.
justynoh Jul 19, 2022
94a815e
chore: fix nits
justynoh Jul 20, 2022
3863028
refactor: consolidate form header and miniheader into dumb components…
justynoh Jul 20, 2022
46982d6
chore: added some comments for clarity.
justynoh Jul 20, 2022
006a2c3
chore: update stories
justynoh Jul 20, 2022
13e733c
chore: updates to miniheader story args
justynoh Jul 20, 2022
83caebb
chore: merge with v2/feat/builder-startpage
justynoh Jul 20, 2022
d99aa03
chore: updates to files due to merge with new v2/feat/builder-startpage
justynoh Jul 20, 2022
ba66aec
fix: update form query upon page mutations
justynoh Jul 21, 2022
788704f
Merge branch 'form-v2/feat/builder-startpage' into form-v2/feat/build…
justynoh Jul 21, 2022
d82cf70
Merge remote-tracking branch 'origin/form-v2/develop' into form-v2/fe…
justynoh Jul 21, 2022
c827acd
Merge remote-tracking branch 'origin/form-v2/feat/builder-startpage-2…
justynoh Jul 21, 2022
52d427d
chore: clean up codebase of excess comments and console logs
justynoh Jul 21, 2022
8cd4640
fix: use previous custom logo meta if logo was not changed.
justynoh Jul 22, 2022
cd44cbd
chore: rename customlogometa
justynoh Jul 22, 2022
86859a0
chore: rename start page data input in design store
justynoh Jul 22, 2022
8ee2454
chore: fix nits
justynoh Jul 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react'
import { useMemo, useState } from 'react'
import { Flex, Skeleton } from '@chakra-ui/react'

import { FormAuthType, FormLogoState } from '~shared/types'
import { FormAuthType, FormLogoState, FormStartPage } from '~shared/types'

import { useEnv } from '~features/env/queries'
import { FormBannerLogo } from '~features/public-form/components/FormStartPage/FormBannerLogo'
Expand All @@ -9,34 +10,87 @@ import { useFormBannerLogo } from '~features/public-form/components/FormStartPag
import { useFormHeader } from '~features/public-form/components/FormStartPage/useFormHeader'

import { useCreateTabForm } from '../useCreateTabForm'
import { startPageDataSelector, useDesignStore } from '../useDesignStore'
import {
customLogoMetaSelector,
startPageDataSelector,
useDesignStore,
} from '../useDesignStore'

export const StartPageView = () => {
const { data: form } = useCreateTabForm()
const startPageFromStore = useDesignStore(startPageDataSelector)
const { startPageData, customLogoMeta } = useDesignStore((state) => ({
startPageData: startPageDataSelector(state),
customLogoMeta: customLogoMetaSelector(state),
}))
const { data: { logoBucketUrl } = {} } = useEnv(
form?.startPage.logo.state === FormLogoState.Custom,
)

const [customLogoPending, setCustomLogoPending] = useState<boolean>(false)

// Transform the FormStartPageInput into a FormStartPage
const startPageFromStore: FormStartPage | null = useMemo(() => {
if (!startPageData) return null
const { logo, estTimeTaken, ...rest } = startPageData
const estTimeTakenTransformed =
estTimeTaken === '' ? undefined : estTimeTaken
if (logo.state !== FormLogoState.Custom) {
setCustomLogoPending(false)
return {
logo: { state: logo.state },
estTimeTaken: estTimeTakenTransformed,
...rest,
}
}
setCustomLogoPending(!startPageData?.attachment.srcUrl)
return {
logo: {
state: FormLogoState.Custom,
// Placeholder values
fileId: customLogoMeta?.fileId ?? '',
fileName: customLogoMeta?.fileName ?? '',
fileSizeInBytes: customLogoMeta?.fileSizeInBytes ?? 0,
},
estTimeTaken: estTimeTakenTransformed,
...rest,
}
}, [startPageData, customLogoMeta])

// When drawer is opened, store is populated. We always want the drawer settings
// to be previewed, so when the store is populated, prioritize that setting.
const startPage = useMemo(
() => (startPageFromStore ? startPageFromStore : form?.startPage),
[startPageFromStore, form?.startPage],
)
const startPage = useMemo(() => {
if (startPageFromStore) return startPageFromStore
setCustomLogoPending(false)
return form?.startPage
}, [form?.startPage, startPageFromStore])

// Color theme options and other design stuff, identical to public form
const { titleColor, titleBg, estTimeString } = useFormHeader(startPage)

const formBannerLogoProps = useFormBannerLogo({
logoBucketUrl, // This will be conditional once the logo field is added.
const { hasLogo, logoImgSrc, logoImgAlt } = useFormBannerLogo({
logoBucketUrl,
logo: startPage?.logo,
agency: form?.admin.agency,
})

return (
<>
<FormBannerLogo {...formBannerLogoProps} />
{customLogoPending ? (
// Show skeleton if user has chosen custom logo but not yet uploaded
<Flex justify="center" p="1rem" bg="white">
<Skeleton w="4rem" h="4rem" />
</Flex>
) : (
<FormBannerLogo
hasLogo={hasLogo}
logoImgSrc={
startPageData?.logo.state === FormLogoState.Custom
? startPageData.attachment.srcUrl // manual override to preview custom logo
: logoImgSrc
}
logoImgAlt={logoImgAlt}
/>
)}
<FormHeader
title={form?.title}
estTimeString={estTimeString}
Expand Down
Loading