import { useRouter } from 'next/router'
import { slug } from 'github-slugger'
import { CheckCircleFillIcon } from '@primer/octicons-react'
import cx from 'classnames'
import { LinkIconHeading } from 'components/article/LinkIconHeading'
import { Link } from 'components/Link'
import { useTranslation } from 'components/hooks/useTranslation'
import { RestPreviewNotice } from './RestPreviewNotice'
import { ParameterTable } from 'components/parameter-table/ParameterTable'
import { RestCodeSamples } from './RestCodeSamples'
import { RestStatusCodes } from './RestStatusCodes'
import { Operation } from './types'
import styles from './RestOperation.module.scss'
type Props = {
operation: Operation
}
// all REST operations have this accept header by default
const DEFAULT_ACCEPT_HEADER = {
name: 'accept',
type: 'string',
description: `
Setting to application/vnd.github+json is recommended.
`,
isRequired: false,
}
export function RestOperation({ operation }: Props) {
const titleSlug = slug(operation.title)
const { t } = useTranslation('products')
const router = useRouter()
const headers = [DEFAULT_ACCEPT_HEADER]
const numPreviews = operation.previews.length
const hasStatusCodes = operation.statusCodes.length > 0
const hasCodeSamples = operation.codeExamples.length > 0
const hasParameters = operation.parameters.length > 0 || operation.bodyParameters.length > 0
return (
{operation.title}
{operation.enabledForGitHubApps && (
{t('rest.reference.works_with') + ' '}
GitHub Apps
)}
{hasParameters && (
)}
{hasStatusCodes && (
)}
{hasCodeSamples && (
)}
{numPreviews > 0 && (
1
? `${t('rest.reference.preview_notices').replace(
'{{ RESTOperationTitle }}',
operation.title
)}`
: `${t('rest.reference.preview_notice').replace(
'{{ RESTOperationTitle }}',
operation.title
)}`
}
/>
)}
)
}