'use client' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine } from '@remixicon/react' import AppIconPicker from '../../base/app-icon-picker' import Modal from '@/app/components/base/modal' import Button from '@/app/components/base/button' import Input from '@/app/components/base/input' import Textarea from '@/app/components/base/textarea' import Switch from '@/app/components/base/switch' import Toast from '@/app/components/base/toast' import AppIcon from '@/app/components/base/app-icon' import { useProviderContext } from '@/context/provider-context' import AppsFull from '@/app/components/billing/apps-full-in-dialog' import type { AppIconType } from '@/types/app' import { SimpleSelect } from '@/app/components/base/select' import { TreeSelect as AntdTreeSelect } from 'antd' import { fetchAppsPermission, fetchDeptUserTree } from '@/service/common' import { GetAppAuth } from '@/app/(commonLayout)/apps/Apps' export type CreateAppModalProps = { app: any show: boolean isEditModal?: boolean appName: string appDescription: string appIconType: AppIconType | null appIcon: string appIconBackground?: string | null appIconUrl?: string | null appMode?: string appUseIconAsAnswerIcon?: boolean onConfirm: (info: { name: string icon_type: AppIconType icon: string icon_background?: string description: string use_icon_as_answer_icon?: boolean editAuth?: number lookUserIds: any[], }) => Promise onHide: () => void } const CreateAppModal = ({ app, show = false, isEditModal = false, appIconType, appIcon: _appIcon, appIconBackground, appIconUrl, appName, appDescription, appMode, appUseIconAsAnswerIcon, onConfirm, onHide, }: CreateAppModalProps) => { const { t } = useTranslation() const { isCreate, isEdit, isOperation } = GetAppAuth(app) const [editAuth, setEditAuth] = useState() const [lookUserIds, setLookUserIds] = useState([]) const [name, setName] = React.useState(appName) const [appIcon, setAppIcon] = useState( () => appIconType === 'image' ? { type: 'image' as const, fileId: _appIcon, url: appIconUrl } : { type: 'emoji' as const, icon: _appIcon, background: appIconBackground }, ) const [showAppIconPicker, setShowAppIconPicker] = useState(false) const [description, setDescription] = useState(appDescription || '') const [useIconAsAnswerIcon, setUseIconAsAnswerIcon] = useState(appUseIconAsAnswerIcon || false) const { plan, enableBilling } = useProviderContext() const isAppsFull = (enableBilling && plan.usage.buildApps >= plan.total.buildApps) const submit = () => { if (!name.trim()) { Toast.notify({ type: 'error', message: t('explore.appCustomize.nameRequired') }) return } onConfirm({ name, icon_type: appIcon.type, icon: appIcon.type === 'emoji' ? appIcon.icon : appIcon.fileId, icon_background: appIcon.type === 'emoji' ? appIcon.background! : undefined, description, use_icon_as_answer_icon: useIconAsAnswerIcon, editAuth, lookUserIds, }) onHide() } const optionsEditAuth = [ { name: '本账号', value: 1 }, { name: '本部门', value: 2 }, ] const [optionsDeptUser, setOptionsDeptUser] = useState([]) useEffect(() => { fetchAppsPermission({ url: `/apps/${app.id}/permission`, }).then((res: any) => { setEditAuth(res.edit_auth) setLookUserIds(res.read_permission.map((v: any) => v.id)) }) }, []) useEffect(() => { fetchDeptUserTree({ url: '/dept/dept-accounts', }).then((res: any) => { const deep = (arr: any) => { return arr.map((v: any) => { v.treeId = v.dept_id || v.account_id v.treeName = v.dept_name || v.email if (v.children?.length > 0) v.treeChildren = deep(v.children) else if (v.account_list?.length > 0) v.treeChildren = deep(v.account_list) return v }) } setOptionsDeptUser(deep(res.data) || []) }) }, []) return ( <> {}} className='relative !max-w-[480px] px-8' >
{isEditModal && (
{t('app.editAppTitle')}
)} {!isEditModal && (
{t('explore.appCustomize.title', { name: appName })}
)}
{/* icon & name */}
{t('app.newApp.captionName')}
{ setShowAppIconPicker(true) }} className='cursor-pointer' iconType={appIcon.type} icon={appIcon.type === 'image' ? appIcon.fileId : appIcon.icon} background={appIcon.type === 'image' ? undefined : appIcon.background} imageUrl={appIcon.type === 'image' ? appIcon.url : undefined} /> setName(e.target.value)} placeholder={t('app.newApp.appNamePlaceholder') || ''} className='h-10 grow' />
{/* description */}
{t('app.newApp.captionDescription')}