Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Merge branch 'main' into updated-templates-view
Mish Ushakov4765dd5608ea
diff --cc apps/web/src/components/Dashboard/Templates.tsxindex c4c2ab427,04b645e04..b962717eb--- a/apps/web/src/components/Dashboard/Templates.tsx+++ b/apps/web/src/components/Dashboard/Templates.tsx@@@ -50,111 -27,31 +51,103 @@@ export function TemplatesContent(}: {user: E2BUserteamId: string+ apiUrl: string}) {const [templates, setTemplates] = useState<Template[]>([])+ const [currentTemplate, setCurrentTemplate] = useState<Template | null>(null)+ const [isPublishTemplateDialogOpen, setIsPublishTemplateDialogOpen] =+ useState(false)+ const [isDeleteTemplateDialogOpen, setIsDeleteTemplateDialogOpen] =+ useState(false)useEffect(() => {- async function fetchTemplates() {- const res = await fetch(- `${process.env.NEXT_PUBLIC_API_URL}/templates?teamID=${teamId}`,- {- method: 'GET',- headers: {- Authorization: `Bearer ${user.accessToken}`,- },- }- )-- const data: Template[] = await res.json()- if (!res.ok) {- toast({- title: 'An error occurred',- description: 'We were unable to fetch the team members',+ function f() {+ const accessToken = user.accessToken+ if (accessToken) {+ fetchTemplates(apiUrl, accessToken, teamId).then((newTemplates) => {+ if (newTemplates) {+ setTemplates(newTemplates)+ }})+ console.log(res.statusText)+ return}- }- const interval = setInterval(() => {- f()- }, 5000)+ // Display the most recently updated templates first+ const orderedData = data.sort((a, b) => {+ return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()+ })+ setTemplates(orderedData)+ }- f()- // Cleanup interval on component unmount- return () => clearInterval(interval)+ fetchTemplates()}, [user, teamId])+ async function deleteTemplate() {+ const res = await fetch(+ `${process.env.NEXT_PUBLIC_API_URL}/templates/${currentTemplate?.templateID}`,+ {+ method: 'DELETE',+ headers: {+ Authorization: `Bearer ${user.accessToken}`,+ },+ }+ )++ if (!res.ok) {+ return toast({+ title: 'An error occurred',+ description: 'We were unable to delete the template',+ })+ }++ setTemplates(+ templates.filter(+ (template) => template.templateID !== currentTemplate?.templateID+ )+ )+ setCurrentTemplate(null)+ setIsDeleteTemplateDialogOpen(false)+ }++ async function publishTemplate() {+ const res = await fetch(+ `${process.env.NEXT_PUBLIC_API_URL}/templates/${currentTemplate?.templateID}`,+ {+ method: 'PATCH',+ headers: {+ Authorization: `Bearer ${user.accessToken}`,+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify({+ public: !currentTemplate?.public,+ }),+ }+ )++ if (!res.ok) {+ return toast({+ title: 'An error occurred',+ description: 'We were unable to update the template',+ })+ }++ toast({+ title: 'Template updated',+ description: 'The template has been updated successfully',+ })++ setTemplates(+ templates.map((template) =>+ template.templateID === currentTemplate?.templateID+ ? { ...template, public: !template.public }+ : template+ )+ )+ setCurrentTemplate(null)+ setIsPublishTemplateDialogOpen(false)+ }+return (<div className="flex flex-col justify-center"><Table>