mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 01:59:03 +08:00
enhancement: improve client-side code (#2568)
This commit is contained in:
parent
fc64cdee64
commit
07fbeb6cf0
@ -3,13 +3,16 @@ import React from 'react'
|
||||
import Spinner from '../spinner'
|
||||
|
||||
export type IButtonProps = {
|
||||
type?: string
|
||||
/**
|
||||
* The style of the button
|
||||
*/
|
||||
type?: 'primary' | 'warning' | (string & {})
|
||||
className?: string
|
||||
disabled?: boolean
|
||||
loading?: boolean
|
||||
tabIndex?: number
|
||||
children: React.ReactNode
|
||||
onClick?: MouseEventHandler<HTMLDivElement>
|
||||
onClick?: MouseEventHandler<HTMLButtonElement>
|
||||
}
|
||||
|
||||
const Button: FC<IButtonProps> = ({
|
||||
@ -35,15 +38,16 @@ const Button: FC<IButtonProps> = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
<button
|
||||
className={`btn ${style} ${className && className}`}
|
||||
tabIndex={tabIndex}
|
||||
onClick={disabled ? undefined : onClick}
|
||||
disabled={disabled}
|
||||
onClick={onClick}
|
||||
>
|
||||
{children}
|
||||
{/* Spinner is hidden when loading is false */}
|
||||
<Spinner loading={loading} className='!text-white !h-3 !w-3 !border-2 !ml-1' />
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React, { useEffect } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import useSWR from 'swr'
|
||||
import PlanComp from '../plan'
|
||||
import { ReceiptList } from '../../base/icons/src/vender/line/financeAndECommerce'
|
||||
import { LinkExternal01 } from '../../base/icons/src/vender/line/general'
|
||||
@ -12,17 +13,11 @@ import { useProviderContext } from '@/context/provider-context'
|
||||
const Billing: FC = () => {
|
||||
const { t } = useTranslation()
|
||||
const { isCurrentWorkspaceManager } = useAppContext()
|
||||
const [billingUrl, setBillingUrl] = React.useState('')
|
||||
const { enableBilling } = useProviderContext()
|
||||
|
||||
useEffect(() => {
|
||||
if (!enableBilling || !isCurrentWorkspaceManager)
|
||||
return
|
||||
(async () => {
|
||||
const { url } = await fetchBillingUrl()
|
||||
setBillingUrl(url)
|
||||
})()
|
||||
}, [isCurrentWorkspaceManager])
|
||||
const { data: billingUrl } = useSWR(
|
||||
(!enableBilling || !isCurrentWorkspaceManager) ? null : ['/billing/invoices'],
|
||||
() => fetchBillingUrl().then(data => data.url),
|
||||
)
|
||||
|
||||
return (
|
||||
<div>
|
||||
@ -39,4 +34,5 @@ const Billing: FC = () => {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default React.memo(Billing)
|
||||
|
@ -138,16 +138,12 @@ export default function AccountSetting({
|
||||
]
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
const [scrolled, setScrolled] = useState(false)
|
||||
const scrollHandle = (e: Event) => {
|
||||
if ((e.target as HTMLDivElement).scrollTop > 0)
|
||||
setScrolled(true)
|
||||
|
||||
else
|
||||
setScrolled(false)
|
||||
}
|
||||
useEffect(() => {
|
||||
const targetElement = scrollRef.current
|
||||
|
||||
const scrollHandle = (e: Event) => {
|
||||
const userScrolled = (e.target as HTMLDivElement).scrollTop > 0
|
||||
setScrolled(userScrolled)
|
||||
}
|
||||
targetElement?.addEventListener('scroll', scrollHandle)
|
||||
return () => {
|
||||
targetElement?.removeEventListener('scroll', scrollHandle)
|
||||
|
Loading…
x
Reference in New Issue
Block a user