diff --git a/app/javascript/components/localization/glossary-entries/list/ProposeTermModal.tsx b/app/javascript/components/localization/glossary-entries/list/ProposeTermModal.tsx new file mode 100644 index 0000000000..df875cc125 --- /dev/null +++ b/app/javascript/components/localization/glossary-entries/list/ProposeTermModal.tsx @@ -0,0 +1,143 @@ +import React from 'react' +import { Modal } from '@/components/modals' +import { sendRequest } from '@/utils/send-request' +import { useContext, useState, useCallback } from 'react' +import toast from 'react-hot-toast' +import { GlossaryEntriesListContext } from '.' +import { LocaleSelect } from './LocaleSelect' + +export function ProposeTermModal({ + isOpen, + onClose, +}: { + isOpen: boolean + onClose: () => void +}) { + const { links, translationLocales } = useContext(GlossaryEntriesListContext) + const [term, setTerm] = useState('') + const [description, setDescription] = useState('') + const [locale, setLocale] = useState(translationLocales[0]) + const [translation, setTranslation] = useState('') + + const onSave = useCallback(() => { + const fetch = sendRequest({ + endpoint: links.createGlossaryEntry, + method: 'POST', + body: JSON.stringify({ + glossary_entry: { + term, + llm_instructions: description, + locale, + translation, + }, + }), + }) + + fetch.fetch + .then(() => { + onClose() + toast.success('Proposed a new term successfully!') + }) + .catch((e) => { + toast.error('Failed to propose a new term.', e) + console.error(e) + }) + }, [term, description, locale, translation]) + + return ( + +
+

Propose New Term

+
+
+ + setTerm(e.target.value)} + className="w-full border border-gray-300 rounded px-12 py-8 mb-8" + placeholder="Enter term" + /> + +

+ A glossary term is a word or phrase that has a specific meaning + within a particular context or field. +

+
+
+ + +

+ A glossary term description provides additional context or + explanation about the term, helping users understand its usage and + significance. +

+
+
+ + setLocale(locale)} + showAll={false} + label="Select locale" + /> +

+ Select the language locale for this glossary term. +

+
+
+ + setTranslation(e.target.value)} + className="w-full border border-gray-300 rounded px-12 py-8 mb-8" + placeholder="Enter translation" + /> +

+ Provide the translated term or phrase in the selected locale. +

+
+
+ + +
+
+
+
+ ) +} diff --git a/app/javascript/components/localization/glossary-entries/list/Table.tsx b/app/javascript/components/localization/glossary-entries/list/Table.tsx index 378e5903e8..7593edc507 100644 --- a/app/javascript/components/localization/glossary-entries/list/Table.tsx +++ b/app/javascript/components/localization/glossary-entries/list/Table.tsx @@ -4,13 +4,12 @@ import React, { useCallback, useContext, useEffect, useState } from 'react' import { GlossaryEntriesListContext } from '.' import { GlossaryEntriesTableList } from './GlossaryEntriesTableList' import { Tabs } from './Tabs' -import { Modal } from '@/components/modals' -import { sendRequest } from '@/utils/send-request' -import { Toaster, toast } from 'react-hot-toast' +import { Toaster } from 'react-hot-toast' import { LocaleSelect } from './LocaleSelect' +import { ProposeTermModal } from './ProposeTermModal' export function Table() { - const { setCriteria, request, translationLocales, setQuery } = + const { setCriteria, request, translationLocales, setQuery, setPage } = React.useContext(GlossaryEntriesListContext) const [isOpen, setIsOpen] = React.useState(false) @@ -25,6 +24,7 @@ export function Table() { useEffect(() => { setCriteria(debouncedValue) + setPage(0) }, [debouncedValue, setCriteria]) return ( @@ -85,139 +85,3 @@ function ProposeTermButton({ onClick }) { ) } - -function ProposeTermModal({ - isOpen, - onClose, -}: { - isOpen: boolean - onClose: () => void -}) { - const { links, translationLocales } = useContext(GlossaryEntriesListContext) - const [term, setTerm] = useState('') - const [description, setDescription] = useState('') - const [locale, setLocale] = useState(translationLocales[0]) - const [translation, setTranslation] = useState('') - - const onSave = useCallback(() => { - const fetch = sendRequest({ - endpoint: links.createGlossaryEntry, - method: 'POST', - body: JSON.stringify({ - glossary_entry: { - term, - llm_instructions: description, - locale, - translation, - }, - }), - }) - - fetch.fetch - .then(() => { - onClose() - toast.success('Proposed a new term successfully!') - }) - .catch((e) => { - toast.error('Failed to propose a new term.', e) - console.error(e) - }) - }, [term, description, locale, translation]) - - return ( - -
-

Propose New Term

-
-
- - setTerm(e.target.value)} - className="w-full border border-gray-300 rounded px-12 py-8 mb-8" - placeholder="Enter term" - /> - -

- A glossary term is a word or phrase that has a specific meaning - within a particular context or field. -

-
-
- - -

- A glossary term description provides additional context or - explanation about the term, helping users understand its usage and - significance. -

-
-
- - setLocale(locale)} - showAll={false} - label="Select locale" - /> -

- Select the language locale for this glossary term. -

-
-
- - setTranslation(e.target.value)} - className="w-full border border-gray-300 rounded px-12 py-8 mb-8" - placeholder="Enter translation" - /> -

- Provide the translated term or phrase in the selected locale. -

-
-
- - -
-
-
-
- ) -}