2026-08-05 20:51:43 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2026-02-24 20:44:16 +00:00
|
|
|
import { useComponents } from '../../contexts/ComponentContext'
|
|
|
|
|
import {
|
|
|
|
|
FaPlus,
|
|
|
|
|
FaSearch,
|
|
|
|
|
FaRegEdit,
|
|
|
|
|
FaTrashAlt,
|
|
|
|
|
FaEye,
|
|
|
|
|
FaEyeSlash,
|
|
|
|
|
FaFilter,
|
|
|
|
|
FaCalendarAlt,
|
2026-08-06 13:17:59 +00:00
|
|
|
FaExternalLinkAlt,
|
|
|
|
|
FaCog,
|
2026-08-05 20:51:43 +00:00
|
|
|
FaSyncAlt,
|
2026-02-24 20:44:16 +00:00
|
|
|
} from 'react-icons/fa'
|
2026-05-12 12:49:25 +00:00
|
|
|
import Widget from '@/components/common/Widget'
|
2026-02-24 20:44:16 +00:00
|
|
|
import { ROUTES_ENUM } from '@/routes/route.constant'
|
|
|
|
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
2026-03-01 20:43:25 +00:00
|
|
|
import { Loading } from '../../components/shared'
|
|
|
|
|
import { APP_NAME } from '@/constants/app.constant'
|
|
|
|
|
import { Helmet } from 'react-helmet'
|
2026-06-25 22:55:44 +00:00
|
|
|
import { Button } from '@/components/ui'
|
2026-08-06 13:17:59 +00:00
|
|
|
import Dialog from '@/components/ui/Dialog'
|
|
|
|
|
import ComponentEditor from './ComponentEditor'
|
2026-08-06 21:19:34 +00:00
|
|
|
import { parseComponentDependencies } from '@/contexts/componentRuntime'
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
const ComponentManager: React.FC = () => {
|
2026-08-06 21:19:34 +00:00
|
|
|
const {
|
|
|
|
|
components,
|
|
|
|
|
loading,
|
|
|
|
|
componentErrors,
|
|
|
|
|
updateComponent,
|
|
|
|
|
deleteComponent,
|
|
|
|
|
refreshComponents,
|
|
|
|
|
} = useComponents()
|
2026-02-24 20:44:16 +00:00
|
|
|
const [searchTerm, setSearchTerm] = useState('')
|
|
|
|
|
const [filterActive, setFilterActive] = useState<'all' | 'active' | 'inactive'>('all')
|
2026-08-05 20:51:43 +00:00
|
|
|
const [isRefreshing, setIsRefreshing] = useState(false)
|
2026-08-06 13:17:59 +00:00
|
|
|
const [editorComponentId, setEditorComponentId] = useState<string | null | undefined>(undefined)
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
// Calculate statistics
|
|
|
|
|
const totalComponents = components?.length || 0
|
|
|
|
|
const activeComponents = components?.filter((c) => c.isActive).length || 0
|
|
|
|
|
const inactiveComponents = totalComponents - activeComponents
|
|
|
|
|
const { translate } = useLocalization()
|
|
|
|
|
|
2026-08-05 20:51:43 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
void refreshComponents()
|
|
|
|
|
}, [refreshComponents])
|
|
|
|
|
|
|
|
|
|
const handleRefresh = async () => {
|
|
|
|
|
setIsRefreshing(true)
|
|
|
|
|
try {
|
|
|
|
|
await refreshComponents()
|
|
|
|
|
} finally {
|
|
|
|
|
setIsRefreshing(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
const filteredComponents = components?.filter((component) => {
|
|
|
|
|
const matchesSearch =
|
|
|
|
|
component.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
|
|
|
(component.description || '').toLowerCase().includes(searchTerm.toLowerCase())
|
|
|
|
|
|
|
|
|
|
const matchesFilter =
|
|
|
|
|
filterActive === 'all' ||
|
|
|
|
|
(filterActive === 'active' && component.isActive) ||
|
|
|
|
|
(filterActive === 'inactive' && !component.isActive)
|
|
|
|
|
|
|
|
|
|
return matchesSearch && matchesFilter
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handleToggleActive = async (id: string, isActive: boolean) => {
|
|
|
|
|
try {
|
|
|
|
|
const component = components?.find((c) => c.id === id)
|
|
|
|
|
if (component) {
|
|
|
|
|
await updateComponent(id, { ...component, isActive })
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Failed to toggle component status:', err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-06 09:44:26 +00:00
|
|
|
const handleDelete = async (id: string) => {
|
2026-02-24 20:44:16 +00:00
|
|
|
if (window.confirm(translate('::App.DeveloperKit.Component.ConfirmDelete'))) {
|
|
|
|
|
try {
|
|
|
|
|
await deleteComponent(id)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Failed to delete component:', err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
2026-03-01 20:43:25 +00:00
|
|
|
<Helmet
|
|
|
|
|
titleTemplate={`%s | ${APP_NAME}`}
|
|
|
|
|
title={translate('::' + 'App.DeveloperKit.Components')}
|
|
|
|
|
defaultTitle={APP_NAME}
|
|
|
|
|
></Helmet>
|
2026-02-24 20:44:16 +00:00
|
|
|
|
2026-03-01 20:43:25 +00:00
|
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mt-2 mb-4">
|
2026-05-12 12:49:25 +00:00
|
|
|
<Widget
|
|
|
|
|
title={translate('::App.DeveloperKit.Component.Total')}
|
|
|
|
|
value={totalComponents}
|
|
|
|
|
color="purple"
|
|
|
|
|
icon="FaPuzzlePiece"
|
|
|
|
|
valueClassName="text-3xl"
|
|
|
|
|
subTitle={translate('::App.DeveloperKit.Component.TotalDescription')}
|
|
|
|
|
/>
|
|
|
|
|
<Widget
|
|
|
|
|
title={translate('::App.DeveloperKit.Component.Active')}
|
|
|
|
|
value={activeComponents}
|
|
|
|
|
color="green"
|
|
|
|
|
icon="FaCheckCircle"
|
|
|
|
|
valueClassName="text-3xl"
|
|
|
|
|
subTitle={translate('::App.DeveloperKit.Component.ActiveDescription')}
|
|
|
|
|
/>
|
|
|
|
|
<Widget
|
|
|
|
|
title={translate('::App.DeveloperKit.Component.Inactive')}
|
|
|
|
|
value={inactiveComponents}
|
|
|
|
|
color="gray"
|
|
|
|
|
icon="FaTimesCircle"
|
|
|
|
|
valueClassName="text-3xl"
|
|
|
|
|
subTitle={translate('::App.DeveloperKit.Component.InactiveDescription')}
|
|
|
|
|
/>
|
2026-02-24 20:44:16 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Filters */}
|
2026-08-06 13:17:59 +00:00
|
|
|
<div className="flex flex-col sm:flex-row gap-3">
|
2026-02-24 20:44:16 +00:00
|
|
|
<div className="flex-1 relative">
|
|
|
|
|
<FaSearch className="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-slate-400" />
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder={translate('::App.DeveloperKit.Component.SearchPlaceholder')}
|
|
|
|
|
value={searchTerm}
|
2026-06-26 08:59:13 +00:00
|
|
|
className="w-full pl-10 pr-2 py-1 border border-slate-300 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
2026-08-05 20:51:43 +00:00
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
2026-02-24 20:44:16 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-05-19 20:22:25 +00:00
|
|
|
<FaFilter className="w-5 h-5 text-slate-500 dark:text-gray-400" />
|
2026-02-24 20:44:16 +00:00
|
|
|
<select
|
|
|
|
|
value={filterActive}
|
2026-06-26 08:59:13 +00:00
|
|
|
className="px-2 py-1 border border-slate-300 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
2026-08-05 20:51:43 +00:00
|
|
|
onChange={(e) => setFilterActive(e.target.value as 'all' | 'active' | 'inactive')}
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
|
|
|
|
<option value="all">{translate('::App.DeveloperKit.Component.Filter.All')}</option>
|
|
|
|
|
<option value="active">
|
|
|
|
|
{translate('::App.DeveloperKit.Component.Filter.Active')}
|
|
|
|
|
</option>
|
|
|
|
|
<option value="inactive">
|
|
|
|
|
{translate('::App.DeveloperKit.Component.Filter.Inactive')}
|
|
|
|
|
</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
2026-08-05 20:51:43 +00:00
|
|
|
<Button
|
|
|
|
|
className="flex items-center gap-2"
|
|
|
|
|
disabled={loading || isRefreshing}
|
|
|
|
|
type="button"
|
|
|
|
|
variant="default"
|
|
|
|
|
onClick={() => void handleRefresh()}
|
|
|
|
|
>
|
|
|
|
|
<FaSyncAlt className={isRefreshing ? 'animate-spin' : ''} />
|
2026-08-06 21:19:34 +00:00
|
|
|
{translate('::App.Platform.Refresh')}
|
2026-08-05 20:51:43 +00:00
|
|
|
</Button>
|
2026-03-01 20:43:25 +00:00
|
|
|
<div>
|
2026-06-26 08:59:13 +00:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="solid"
|
|
|
|
|
className="flex items-center gap-2"
|
2026-08-06 13:17:59 +00:00
|
|
|
onClick={() => setEditorComponentId(null)}
|
2026-03-01 20:43:25 +00:00
|
|
|
>
|
|
|
|
|
<FaPlus className="w-4 h-4" />
|
|
|
|
|
{translate('::App.DeveloperKit.Component.New')}
|
2026-06-26 08:59:13 +00:00
|
|
|
</Button>
|
2026-03-01 20:43:25 +00:00
|
|
|
</div>
|
2026-02-24 20:44:16 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Components List */}
|
|
|
|
|
{loading ? (
|
|
|
|
|
<div className="flex items-center justify-center min-h-screen bg-gray-50">
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
<Loading loading={loading} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : filteredComponents?.length > 0 ? (
|
|
|
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-4 gap-6">
|
|
|
|
|
{filteredComponents.map((component) => (
|
|
|
|
|
<div
|
|
|
|
|
key={component.id}
|
2026-05-19 20:22:25 +00:00
|
|
|
className="bg-white dark:bg-gray-900 rounded-lg border border-slate-200 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow"
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
|
|
|
|
<div className="p-6">
|
|
|
|
|
<div className="flex items-start justify-between">
|
|
|
|
|
{/* Sol taraf */}
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<div className="flex items-center gap-2 mb-1">
|
2026-07-11 20:35:32 +00:00
|
|
|
<h3 className="text-lg font-semibold text-slate-900 dark:text-gray-100">
|
|
|
|
|
{component.name}
|
|
|
|
|
</h3>
|
2026-02-24 20:44:16 +00:00
|
|
|
<div
|
|
|
|
|
className={`w-2 h-2 rounded-full ${
|
2026-05-19 20:22:25 +00:00
|
|
|
component.isActive ? 'bg-green-500' : 'bg-slate-300 dark:bg-gray-700'
|
2026-02-24 20:44:16 +00:00
|
|
|
}`}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-11 20:35:32 +00:00
|
|
|
<p className="text-slate-600 dark:text-gray-300 text-sm mb-2">
|
2026-08-06 21:19:34 +00:00
|
|
|
{parseComponentDependencies(component.dependencies).join(', ') ||
|
|
|
|
|
translate('::App.DeveloperKit.Component.NoDependencies')}
|
2026-02-24 20:44:16 +00:00
|
|
|
</p>
|
|
|
|
|
|
2026-07-11 20:35:32 +00:00
|
|
|
<p className="text-slate-600 dark:text-gray-300 text-sm mb-2">
|
|
|
|
|
{component.routePath}
|
|
|
|
|
</p>
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
{component.description && (
|
2026-07-11 20:35:32 +00:00
|
|
|
<p className="text-slate-600 dark:text-gray-300 text-sm mb-2">
|
|
|
|
|
{component.description}
|
|
|
|
|
</p>
|
2026-02-24 20:44:16 +00:00
|
|
|
)}
|
2026-08-06 21:19:34 +00:00
|
|
|
|
|
|
|
|
{componentErrors[component.name] && (
|
|
|
|
|
<p
|
|
|
|
|
className="text-xs text-red-700 dark:text-red-300 bg-red-50 dark:bg-red-950 border border-red-200 dark:border-red-800 rounded px-2 py-1 mb-2 break-words"
|
|
|
|
|
title={componentErrors[component.name]}
|
|
|
|
|
>
|
|
|
|
|
{componentErrors[component.name]}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2026-02-24 20:44:16 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Sağ taraf */}
|
|
|
|
|
{component.lastModificationTime && (
|
2026-05-19 20:22:25 +00:00
|
|
|
<div className="flex items-center gap-1 text-xs text-slate-500 dark:text-gray-400 ml-4 whitespace-nowrap">
|
2026-02-24 20:44:16 +00:00
|
|
|
<FaCalendarAlt className="w-3 h-3" />
|
|
|
|
|
<span>
|
|
|
|
|
{new Date(component.lastModificationTime).toLocaleDateString() ?? ''}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Actions */}
|
2026-05-19 20:22:25 +00:00
|
|
|
<div className="flex items-center justify-between pt-2 border-t border-slate-100 dark:border-gray-700">
|
2026-02-24 20:44:16 +00:00
|
|
|
<div className="flex items-center gap-2">
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="plain"
|
2026-06-26 08:59:13 +00:00
|
|
|
shape="circle"
|
|
|
|
|
className={`!inline-flex !h-auto items-center gap-1 rounded !px-2 py-1 text-xs font-medium transition-colors`}
|
2026-08-05 20:51:43 +00:00
|
|
|
onClick={() => handleToggleActive(component.id, !component.isActive)}
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
|
|
|
|
{component.isActive ? (
|
|
|
|
|
<>
|
2026-07-06 09:44:26 +00:00
|
|
|
<FaEye className="w-4 h-4" />
|
|
|
|
|
{translate('::App.Status.Active')}
|
2026-02-24 20:44:16 +00:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2026-07-06 09:44:26 +00:00
|
|
|
<FaEyeSlash className="w-4 h-4" />
|
|
|
|
|
{translate('::App.Status.Inactive')}
|
2026-02-24 20:44:16 +00:00
|
|
|
</>
|
|
|
|
|
)}
|
2026-06-25 22:55:44 +00:00
|
|
|
</Button>
|
2026-02-24 20:44:16 +00:00
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-1">
|
2026-07-13 08:39:13 +00:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="solid"
|
2026-06-26 08:59:13 +00:00
|
|
|
color="blue-600"
|
2026-08-05 20:51:43 +00:00
|
|
|
title={translate('::Edit')}
|
2026-06-26 08:59:13 +00:00
|
|
|
onClick={() =>
|
|
|
|
|
window.open(
|
|
|
|
|
ROUTES_ENUM.protected.saas.developerKit.componentsEdit.replace(
|
|
|
|
|
':id',
|
|
|
|
|
component.id,
|
|
|
|
|
),
|
|
|
|
|
'_blank',
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
2026-08-05 20:51:43 +00:00
|
|
|
<FaRegEdit className="w-4 h-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="solid"
|
|
|
|
|
color="gray-600"
|
|
|
|
|
disabled={!component.isActive || !component.routePath?.trim()}
|
|
|
|
|
title={translate('::OpenUrl')}
|
2026-08-06 09:16:10 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
const routePath = component.routePath.startsWith('/')
|
|
|
|
|
? component.routePath
|
|
|
|
|
: `/${component.routePath}`
|
|
|
|
|
window.open(routePath, '_blank')
|
|
|
|
|
}}
|
2026-08-05 20:51:43 +00:00
|
|
|
>
|
2026-08-06 13:17:59 +00:00
|
|
|
<FaExternalLinkAlt className="w-4 h-4" />
|
2026-06-26 08:59:13 +00:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="solid"
|
|
|
|
|
color="green-600"
|
2026-08-05 20:51:43 +00:00
|
|
|
title={translate('::App.Platform.View')}
|
2026-08-06 13:17:59 +00:00
|
|
|
onClick={() => setEditorComponentId(component.id)}
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
2026-08-06 13:17:59 +00:00
|
|
|
<FaCog className="w-4 h-4" />
|
2026-06-26 08:59:13 +00:00
|
|
|
</Button>
|
2026-06-25 22:55:44 +00:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
2026-06-26 08:59:13 +00:00
|
|
|
variant="solid"
|
|
|
|
|
color="red-600"
|
2026-07-13 08:39:13 +00:00
|
|
|
title={translate('::Delete')}
|
2026-08-05 20:51:43 +00:00
|
|
|
onClick={() => handleDelete(component.id)}
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
2026-08-05 20:51:43 +00:00
|
|
|
<FaTrashAlt className="w-4 h-4" />
|
2026-06-25 22:55:44 +00:00
|
|
|
</Button>
|
2026-02-24 20:44:16 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="text-center py-12">
|
|
|
|
|
<div className="mx-auto">
|
|
|
|
|
<div className="bg-slate-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-4">
|
|
|
|
|
<FaPlus className="w-8 h-8 text-slate-500" />
|
|
|
|
|
</div>
|
|
|
|
|
<h3 className="text-lg font-medium text-slate-900 mb-2">
|
|
|
|
|
{searchTerm || filterActive !== 'all'
|
|
|
|
|
? translate('::App.DeveloperKit.Component.Empty.Filtered.Title')
|
|
|
|
|
: translate('::App.DeveloperKit.Component.Empty.Initial.Title')}
|
|
|
|
|
</h3>
|
|
|
|
|
<p className="text-slate-600 mb-6">
|
|
|
|
|
{searchTerm || filterActive !== 'all'
|
|
|
|
|
? translate('::App.DeveloperKit.EmptyFilteredDescription')
|
|
|
|
|
: translate('::App.DeveloperKit.Component.Empty.Initial.Description')}
|
|
|
|
|
</p>
|
|
|
|
|
{!searchTerm && filterActive === 'all' && (
|
2026-08-06 13:17:59 +00:00
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-02-24 20:44:16 +00:00
|
|
|
className="inline-flex items-center gap-2 bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors"
|
2026-08-06 21:19:34 +00:00
|
|
|
onClick={() => setEditorComponentId(null)}
|
2026-02-24 20:44:16 +00:00
|
|
|
>
|
|
|
|
|
<FaPlus className="w-4 h-4" />
|
|
|
|
|
{translate('::App.DeveloperKit.Component.Empty.Initial.Action')}
|
2026-08-06 13:17:59 +00:00
|
|
|
</button>
|
2026-02-24 20:44:16 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-08-06 13:17:59 +00:00
|
|
|
|
|
|
|
|
<Dialog
|
|
|
|
|
isOpen={editorComponentId !== undefined}
|
|
|
|
|
width={720}
|
|
|
|
|
height="85vh"
|
|
|
|
|
contentClassName="overflow-y-auto"
|
|
|
|
|
onClose={() => setEditorComponentId(undefined)}
|
|
|
|
|
onRequestClose={() => setEditorComponentId(undefined)}
|
|
|
|
|
>
|
|
|
|
|
<ComponentEditor
|
|
|
|
|
key={editorComponentId ?? 'new'}
|
|
|
|
|
componentId={editorComponentId}
|
|
|
|
|
onClose={() => setEditorComponentId(undefined)}
|
|
|
|
|
onSaved={refreshComponents}
|
|
|
|
|
/>
|
|
|
|
|
</Dialog>
|
2026-02-24 20:44:16 +00:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ComponentManager
|