Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { PageHeader } from '@/components/page-header';
  2. import { useSetModalState } from '@/hooks/common-hooks';
  3. import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
  4. import { useFetchAgentTemplates, useSetAgent } from '@/hooks/use-agent-request';
  5. import { IFlowTemplate } from '@/interfaces/database/flow';
  6. import { useCallback, useState } from 'react';
  7. import { useTranslation } from 'react-i18next';
  8. import { CreateAgentDialog } from './create-agent-dialog';
  9. import { TemplateCard } from './template-card';
  10. export default function AgentTemplates() {
  11. const { navigateToAgentList } = useNavigatePage();
  12. const { t } = useTranslation();
  13. const list = useFetchAgentTemplates();
  14. const { loading, setAgent } = useSetAgent();
  15. const {
  16. visible: creatingVisible,
  17. hideModal: hideCreatingModal,
  18. showModal: showCreatingModal,
  19. } = useSetModalState();
  20. const [template, setTemplate] = useState<IFlowTemplate>();
  21. const showModal = useCallback(
  22. (record: IFlowTemplate) => {
  23. setTemplate(record);
  24. showCreatingModal();
  25. },
  26. [showCreatingModal],
  27. );
  28. const { navigateToAgent } = useNavigatePage();
  29. const handleOk = useCallback(
  30. async (payload: any) => {
  31. let dsl = template?.dsl;
  32. const ret = await setAgent({
  33. title: payload.name,
  34. dsl,
  35. avatar: template?.avatar,
  36. });
  37. if (ret?.code === 0) {
  38. hideCreatingModal();
  39. navigateToAgent(ret.data.id)();
  40. }
  41. },
  42. [
  43. hideCreatingModal,
  44. navigateToAgent,
  45. setAgent,
  46. template?.avatar,
  47. template?.dsl,
  48. ],
  49. );
  50. return (
  51. <section>
  52. <PageHeader
  53. back={navigateToAgentList}
  54. title={t('flow.createGraph')}
  55. ></PageHeader>
  56. <div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-6 2xl:grid-cols-8 max-h-[94vh] overflow-auto px-8">
  57. {list?.map((x) => {
  58. return (
  59. <TemplateCard
  60. key={x.id}
  61. data={x}
  62. showModal={showModal}
  63. ></TemplateCard>
  64. );
  65. })}
  66. </div>
  67. {creatingVisible && (
  68. <CreateAgentDialog
  69. loading={loading}
  70. visible={creatingVisible}
  71. hideModal={hideCreatingModal}
  72. onOk={handleOk}
  73. ></CreateAgentDialog>
  74. )}
  75. </section>
  76. );
  77. }