import { memo } from 'react'
import { NavBarTitle } from './navigation'
import { useInputHeader } from './hooks'
import { Link } from './link'
import { Button } from './buttons/button'
import { InputHeaders } from './forms/input-headers'
import { useWebsiteData } from '@app/data'
import { GrClose } from 'react-icons/gr'
import { AppManager } from '@app/managers'
import { FeedIssue } from './feed/issue'
import { Header3 } from './header'
import { HeadlessFullScreenModal } from '../modal/headless-full'
import { fetcher } from '@app/utils/fetcher'
import { LineChart } from './charts/line-chart'
import { Lighthouse } from './lighthouse'
export const defaultModalState = {
open: false,
data: null,
title: '',
url: '',
error: '',
}
function UpperInput({ data, url }: any) {
const { customFields, removeFormField, addFormField, updateFormField } =
useInputHeader(data)
const customHeaders = customFields?.map((item: any) => {
return {
key: item?.key,
value: item?.value,
}
})
const { updateWebsite } = useWebsiteData('', url, customHeaders, true)
const inputProps = {
customHeader: true,
customFields,
removeFormField,
addFormField,
updateFormField,
}
const onUpdateWebsite = async () => {
try {
await updateWebsite({
variables: { url, customHeaders, filter: '' },
})
AppManager.toggleSnack(
true,
'Headers updated successfully.',
'message',
true
)
// todo find website and apply headers
} catch (e) {
AppManager.toggleSnack(true, e, 'error')
}
}
return (
Update
)
}
interface FullScreenModalProps {
open: boolean
role?: number
handleClose(x?: any): any
handleClickOpen?(data: any, title: any, url: any, error: any): any
handleClickOpenPlayer?(x?: any): any
refetch(x?: any): any
error?: string
title?: string
url: string
data?: any
}
// handle the type of modal that should be displayed. Todo: use enum
const handleModelType = (title: string) => {
const issuesModal = title === 'Issues'
const headerModal = title === 'Custom Headers'
const verifyModal = title === 'Verify DNS'
const analyticsModal = title === 'Website Analytics'
return {
issuesModal,
headerModal,
verifyModal,
analyticsModal,
}
}
// todo: split props into component
const Body = ({
data,
title = 'Issues',
// onPress,
refetch,
url,
onDnsStatusEvent,
error,
}: Partial) => {
const { issuesModal, headerModal, verifyModal, analyticsModal } =
handleModelType(title)
if (title === 'Lighthouse') {
return (
)
}
if (analyticsModal) {
const analytics = data?.data
return (
)
}
if (verifyModal) {
const textRecord = data?.data?.txtRecord
return (
Verify DNS
Enter the following .txt record to confirm your domain. You can
remove the record after confirmation.
By verifying your domain, you can enable the CDN to store content.
If you need help please, contact support for alternative validation
steps.
{textRecord ? (
<>
>
) : (
{data?.message}
)}
Check Status
)
}
if (headerModal) {
return
}
// TODO: remove for different way of determine issues content.
const isFlatIssues =
data && Array.isArray(data) && data?.some((o) => 'domain' in o == false)
if (issuesModal && isFlatIssues) {
return (
{data?.map((item: any, listIndex: number) => {
return (
)
})}
)
}
return (
No data found yet, please try again later or reload the page.
{refetch ? (
refetch()}
>
Reload Data
) : null}
)
}
export function FullScreenModalWrapper(props: FullScreenModalProps) {
const {
handleClose,
open,
data,
title = 'Issues',
// onPress,
refetch,
url,
error,
} = props
const issuesModal = title === 'Issues'
const issueCount = data?.length
// check to see if the dns was confirmed
const onDnsStatusEvent = async () => {
const domain = new URL(url).hostname
const source = await fetcher('/website/dns', { domain }, 'POST')
AppManager.toggleSnack(
open,
`${domain} is ${!source?.data?.verified ? 'not ' : ''}verified`,
!source?.data?.verified ? 'error' : 'message'
)
if (source?.data?.verified && refetch && handleClose) {
refetch()
handleClose()
}
}
return (
{url ? (
{url}
{issueCount && issuesModal ? (
{issueCount} {issuesModal && error ? 'issue' : 'page'}
{issueCount === 1 ? '' : 's'}
) : null}
) : null}
)
}
export const FullScreenModal = memo(FullScreenModalWrapper)