feat: enhance SuccessModal and conditional rendering for login and subscription options
This commit is contained in:
parent
82c0894ccd
commit
b0f96c33a5
@ -6,10 +6,13 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@headlessui/react'
|
} from '@headlessui/react'
|
||||||
import type { ReactNode } from 'react'
|
import type { ReactNode } from 'react'
|
||||||
|
import { useRouteLoaderData } from 'react-router'
|
||||||
|
|
||||||
import { LeftArrow } from '~/components/icons/left-arrow'
|
import { LeftArrow } from '~/components/icons/left-arrow'
|
||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
import { APP } from '~/configs/meta'
|
import { APP } from '~/configs/meta'
|
||||||
|
import { useNewsContext } from '~/contexts/news'
|
||||||
|
import type { loader } from '~/routes/_layout'
|
||||||
|
|
||||||
export type ModalProperties = {
|
export type ModalProperties = {
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
@ -31,6 +34,10 @@ const DESCRIPTIONS: DescriptionMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SuccessModal = ({ isOpen, onClose }: ModalProperties) => {
|
export const SuccessModal = ({ isOpen, onClose }: ModalProperties) => {
|
||||||
|
const { setIsLoginOpen, setIsInitSubscribeOpen } = useNewsContext()
|
||||||
|
const loaderData = useRouteLoaderData<typeof loader>('routes/_layout')
|
||||||
|
const userToken = loaderData?.userToken
|
||||||
|
|
||||||
const message = isOpen
|
const message = isOpen
|
||||||
? DESCRIPTIONS[isOpen]
|
? DESCRIPTIONS[isOpen]
|
||||||
: 'Terjadi kesalahan. Silakan coba lagi.'
|
: 'Terjadi kesalahan. Silakan coba lagi.'
|
||||||
@ -74,10 +81,10 @@ export const SuccessModal = ({ isOpen, onClose }: ModalProperties) => {
|
|||||||
|
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div className="relative flex flex-col items-center justify-center">
|
<div className="relative flex flex-col items-center justify-center">
|
||||||
<div className="mb-4 p-4 text-center">
|
{['resetPassword', 'register', 'payment'].includes(
|
||||||
{isOpen &&
|
isOpen || '',
|
||||||
['resetPassword', 'register', 'payment'].includes(isOpen) && (
|
) && (
|
||||||
<div className="justify-center">
|
<>
|
||||||
<img
|
<img
|
||||||
src={'/images/back-to-home.svg'}
|
src={'/images/back-to-home.svg'}
|
||||||
alt={APP.title}
|
alt={APP.title}
|
||||||
@ -85,37 +92,45 @@ export const SuccessModal = ({ isOpen, onClose }: ModalProperties) => {
|
|||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
className="mt-5 w-full rounded-md"
|
className="mt-5 w-full rounded-md"
|
||||||
variant={'newsPrimary'}
|
variant="newsPrimary"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
>
|
>
|
||||||
Back to Home
|
Back to Home
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</>
|
||||||
)}
|
)}
|
||||||
{isOpen === 'warning' && (
|
{isOpen === 'warning' && (
|
||||||
<div className="justify-center">
|
<>
|
||||||
<img
|
<img
|
||||||
src={'/images/warning.svg'}
|
src={'/images/warning.svg'}
|
||||||
alt={APP.title}
|
alt={APP.title}
|
||||||
className="h-[300px]"
|
className="h-[300px]"
|
||||||
/>
|
/>
|
||||||
<div>
|
{userToken ? (
|
||||||
<Button
|
<Button
|
||||||
className="mt-5 w-full rounded-md"
|
className="mt-5 w-full rounded-md"
|
||||||
variant={'newsPrimary'}
|
variant="newsSecondary"
|
||||||
>
|
onClick={() => {
|
||||||
Login
|
onClose()
|
||||||
</Button>
|
setIsInitSubscribeOpen(true)
|
||||||
<Button
|
}}
|
||||||
className="mt-5 w-full rounded-md"
|
|
||||||
variant={'newsSecondary'}
|
|
||||||
>
|
>
|
||||||
Select Subscription
|
Select Subscription
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
) : (
|
||||||
</div>
|
<Button
|
||||||
|
className="mt-5 w-full rounded-md"
|
||||||
|
variant="newsPrimary"
|
||||||
|
onClick={() => {
|
||||||
|
onClose()
|
||||||
|
setIsLoginOpen(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DialogPanel>
|
</DialogPanel>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user