Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

5.1 KB
Raw Blame
'use client'

import { Button, buttonVariants } from '@langgenius/dify-ui/button'
import {
  Dialog,
  DialogBody,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogHeaderCloseButton,
  DialogTitle,
} from '@langgenius/dify-ui/dialog'
import { useSuspenseQuery } from '@tanstack/react-query'
import { useQueryState } from 'nuqs'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import {
  pricingQueryParamName,
  pricingQueryParser,
} from '@/app/components/billing/pricing/query-params'
import { useDocLink } from '@/context/i18n'
import { systemFeaturesQueryOptions } from '@/features/system-features/client'
import useTimestamp from '@/hooks/use-timestamp'
import Link from '@/next/link'

type ExpireNoticeModalPayloadProps = {
  expireAt: number
  expired: boolean
}
type Props = {
  onClose: () => void
} & ExpireNoticeModalPayloadProps

const i18nPrefix = 'notice'

const ExpireNoticeModal: React.FC<Props> = ({ expireAt, expired, onClose }) => {
  const { t } = useTranslation(['common', 'education'])
  const { data: deploymentEdition } = useSuspenseQuery({
    ...systemFeaturesQueryOptions(),
    select: ({ deployment_edition }) => deployment_edition,
  })
  const docLink = useDocLink()
  const eduDocLink = docLink('/use-dify/workspace/subscription-management#dify-for-education')
  const { formatTime } = useTimestamp()
  const [, setPricing] = useQueryState(pricingQueryParamName, pricingQueryParser)

  return (
    <Dialog
      open
      onOpenChange={(open) => {
        if (!open) onClose()
      }}
    >
      <DialogContent className="w-150">
        <DialogHeader>
          <DialogTitle>
            {expired
              ? t(($) => $[`${i18nPrefix}.expired.title`], { ns: 'education' })
              : t(($) => $[`${i18nPrefix}.isAboutToExpire.title`], {
                  ns: 'education',
                  date: formatTime(
                    expireAt,
                    t(($) => $[`${i18nPrefix}.dateFormat`], { ns: 'education' }) as string,
                  ),
                  interpolation: { escapeValue: false },
                })}
          </DialogTitle>
          <DialogHeaderCloseButton aria-label={t(($) => $['operation.close'], { ns: 'common' })} />
        </DialogHeader>

        <DialogBody>
          <div className="space-y-5 body-md-regular text-text-secondary">
            <div>
              {expired ? (
                <>
                  <div>
                    {t(($) => $[`${i18nPrefix}.expired.summary.line1`], { ns: 'education' })}
                  </div>
                  <div>
                    {t(($) => $[`${i18nPrefix}.expired.summary.line2`], { ns: 'education' })}
                  </div>
                </>
              ) : (
                t(($) => $[`${i18nPrefix}.isAboutToExpire.summary`], { ns: 'education' })
              )}
            </div>
            <div>
              <strong className="block title-md-semi-bold">
                {t(($) => $[`${i18nPrefix}.stillInEducation.title`], { ns: 'education' })}
              </strong>
              {t(
                ($) =>
                  $[`${i18nPrefix}.stillInEducation.${expired ? 'expired' : 'isAboutToExpire'}`],
                { ns: 'education' },
              )}
            </div>
            <div>
              <strong className="block title-md-semi-bold">
                {t(($) => $[`${i18nPrefix}.alreadyGraduated.title`], { ns: 'education' })}
              </strong>
              {t(
                ($) =>
                  $[`${i18nPrefix}.alreadyGraduated.${expired ? 'expired' : 'isAboutToExpire'}`],
                { ns: 'education' },
              )}
            </div>
          </div>
        </DialogBody>
        <DialogFooter>
          <Link
            className="me-auto flex items-center space-x-1 system-xs-regular text-text-accent"
            href={eduDocLink}
            target="_blank"
            rel="noopener noreferrer"
          >
            <span>{t(($) => $.learn, { ns: 'education' })}</span>
            <span className="i-ri-external-link-line size-3" aria-hidden="true" />
          </Link>
          {expired && deploymentEdition === 'CLOUD' ? (
            <Button
              onClick={() => {
                onClose()
                setPricing('open')
              }}
              className="flex items-center"
            >
              <span
                className="i-custom-public-common-sparkles-soft-accent size-4"
                aria-hidden="true"
              />
              <span className="text-components-button-secondary-accent-text">
                {t(($) => $[`${i18nPrefix}.action.upgrade`], { ns: 'education' })}
              </span>
            </Button>
          ) : (
            <Button onClick={onClose}>
              {t(($) => $[`${i18nPrefix}.action.dismiss`], { ns: 'education' })}
            </Button>
          )}
          <Link
            className={buttonVariants({ variant: 'primary' })}
            href="/education/verify"
            onClick={onClose}
          >
            {t(($) => $[`${i18nPrefix}.action.reVerify`], { ns: 'education' })}
          </Link>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}

export default React.memo(ExpireNoticeModal)