AiAssistantManegementModal.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import React, { useCallback, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import {
  4. Modal, ModalHeader, ModalBody, ModalFooter, Form, FormGroup, Label, Input,
  5. } from 'reactstrap';
  6. import type { IPageForItem } from '~/interfaces/page';
  7. import { usePageSelectModal } from '~/stores/modal';
  8. import { useAiAssistantManegementModal } from '../../stores/ai-assistant';
  9. import styles from './AiAssistantManegementModal.module.scss';
  10. const moduleClass = styles['grw-ai-assistant-manegement'] ?? '';
  11. const SelectedPageList = ({ selectedPages }: { selectedPages: IPageForItem[] }): JSX.Element => {
  12. if (selectedPages.length === 0) {
  13. return <></>;
  14. }
  15. return (
  16. <div className="mb-3">
  17. {selectedPages.map(page => (
  18. <p key={page._id} className="mb-1">
  19. <code>{ page.path }</code>
  20. </p>
  21. ))}
  22. </div>
  23. );
  24. };
  25. const AiAssistantManegementModalSubstance = (): JSX.Element => {
  26. const { open: openPageSelectModal } = usePageSelectModal();
  27. const [selectedPages, setSelectedPages] = useState<IPageForItem[]>([]);
  28. const onClickOpenPageSelectModalButton = useCallback(() => {
  29. const onSelected = (page: IPageForItem) => {
  30. setSelectedPages([...selectedPages, page]);
  31. };
  32. openPageSelectModal({ onSelected });
  33. }, [openPageSelectModal, selectedPages]);
  34. return (
  35. <div className="px-4">
  36. <ModalBody>
  37. <Form>
  38. <FormGroup className="mb-4">
  39. <Label className="mb-2 ">アシスタント名</Label>
  40. <Input
  41. type="text"
  42. placeholder="アシスタント名を入力"
  43. className="border rounded"
  44. />
  45. </FormGroup>
  46. <FormGroup className="mb-4">
  47. <div className="d-flex align-items-center mb-2">
  48. <Label className="mb-0">アシスタントの種類</Label>
  49. <span className="ms-1 fs-5 material-symbols-outlined text-secondary">help</span>
  50. </div>
  51. <div className="d-flex gap-4">
  52. <FormGroup check>
  53. <Input type="checkbox" defaultChecked />
  54. <Label check>ナレッジアシスタント</Label>
  55. </FormGroup>
  56. <FormGroup check>
  57. <Input type="checkbox" />
  58. <Label check>エディタアシスタント</Label>
  59. </FormGroup>
  60. <FormGroup check>
  61. <Input type="checkbox" />
  62. <Label check>ラーニングアシスタント</Label>
  63. </FormGroup>
  64. </div>
  65. </FormGroup>
  66. <FormGroup className="mb-4">
  67. <div className="d-flex align-items-center mb-2">
  68. <Label className="mb-0">共有範囲</Label>
  69. <span className="ms-1 fs-5 material-symbols-outlined text-secondary">help</span>
  70. </div>
  71. <Input type="select" className="border rounded w-50">
  72. <option>自分のみ</option>
  73. </Input>
  74. </FormGroup>
  75. <FormGroup className="mb-4">
  76. <div className="d-flex align-items-center mb-2">
  77. <Label className="mb-0">参照するページ</Label>
  78. <span className="ms-1 fs-5 material-symbols-outlined text-secondary">help</span>
  79. </div>
  80. <SelectedPageList selectedPages={selectedPages} />
  81. <button
  82. type="button"
  83. className="btn btn-outline-primary d-flex align-items-center gap-1"
  84. onClick={onClickOpenPageSelectModalButton}
  85. >
  86. <span>+</span>
  87. 追加する
  88. </button>
  89. </FormGroup>
  90. <FormGroup>
  91. <div className="d-flex align-items-center mb-2">
  92. <Label className="mb-0">アシスタントの役割</Label>
  93. <span className="ms-1 fs-5 material-symbols-outlined text-secondary">help</span>
  94. </div>
  95. <Input
  96. type="textarea"
  97. placeholder="アシスタントの役割をいれてください"
  98. className="border rounded"
  99. rows={4}
  100. />
  101. </FormGroup>
  102. </Form>
  103. </ModalBody>
  104. <ModalFooter className="border-0 pt-0 mb-3">
  105. <button type="button" className="btn btn-outline-secondary" onClick={() => {}}>キャンセル</button>
  106. <button type="button" className="btn btn-primary" onClick={() => {}}>作成</button>
  107. </ModalFooter>
  108. </div>
  109. );
  110. };
  111. export const AiAssistantManegementModal = (): JSX.Element => {
  112. const { t } = useTranslation();
  113. const { data: aiAssistantManegementModalData, close: closeAiAssistantManegementModal } = useAiAssistantManegementModal();
  114. const isOpened = aiAssistantManegementModalData?.isOpened ?? false;
  115. return (
  116. <Modal size="lg" isOpen={isOpened} toggle={closeAiAssistantManegementModal} className={moduleClass} scrollable>
  117. <ModalHeader tag="h4" toggle={closeAiAssistantManegementModal} className="pe-4">
  118. <span className="growi-custom-icons growi-ai-assistant-icon me-3 fs-4">ai_assistant</span>
  119. <span className="fw-bold">新規アシスタントの追加</span> {/* TODO i18n */}
  120. </ModalHeader>
  121. { isOpened && (
  122. <AiAssistantManegementModalSubstance />
  123. ) }
  124. </Modal>
  125. );
  126. };