diff --git a/.yarn/cache/@babel-runtime-npm-7.26.0-9afa3c4ef6-c8e2c0504a.zip b/.yarn/cache/@babel-runtime-npm-7.26.0-9afa3c4ef6-c8e2c0504a.zip new file mode 100644 index 000000000..4b9e5e548 Binary files /dev/null and b/.yarn/cache/@babel-runtime-npm-7.26.0-9afa3c4ef6-c8e2c0504a.zip differ diff --git a/.yarn/cache/@emotion-cache-npm-11.13.5-3969859612-d4429bcac0.zip b/.yarn/cache/@emotion-cache-npm-11.13.5-3969859612-d4429bcac0.zip new file mode 100644 index 000000000..f11085ab8 Binary files /dev/null and b/.yarn/cache/@emotion-cache-npm-11.13.5-3969859612-d4429bcac0.zip differ diff --git a/.yarn/cache/@emotion-hash-npm-0.9.2-21b49040cb-379bde2830.zip b/.yarn/cache/@emotion-hash-npm-0.9.2-21b49040cb-379bde2830.zip new file mode 100644 index 000000000..ff06dcb0e Binary files /dev/null and b/.yarn/cache/@emotion-hash-npm-0.9.2-21b49040cb-379bde2830.zip differ diff --git a/.yarn/cache/@emotion-memoize-npm-0.9.0-ccd80906b3-0381323593.zip b/.yarn/cache/@emotion-memoize-npm-0.9.0-ccd80906b3-0381323593.zip new file mode 100644 index 000000000..f3f63843f Binary files /dev/null and b/.yarn/cache/@emotion-memoize-npm-0.9.0-ccd80906b3-0381323593.zip differ diff --git a/.yarn/cache/@emotion-serialize-npm-1.3.3-b390a9707a-5103312337.zip b/.yarn/cache/@emotion-serialize-npm-1.3.3-b390a9707a-5103312337.zip new file mode 100644 index 000000000..c4b0b9db4 Binary files /dev/null and b/.yarn/cache/@emotion-serialize-npm-1.3.3-b390a9707a-5103312337.zip differ diff --git a/.yarn/cache/@emotion-sheet-npm-1.4.0-fb64d8f222-eeb1212e32.zip b/.yarn/cache/@emotion-sheet-npm-1.4.0-fb64d8f222-eeb1212e32.zip new file mode 100644 index 000000000..ccfb33900 Binary files /dev/null and b/.yarn/cache/@emotion-sheet-npm-1.4.0-fb64d8f222-eeb1212e32.zip differ diff --git a/.yarn/cache/@emotion-unitless-npm-0.10.0-bd15580251-d79346df31.zip b/.yarn/cache/@emotion-unitless-npm-0.10.0-bd15580251-d79346df31.zip new file mode 100644 index 000000000..9c745a858 Binary files /dev/null and b/.yarn/cache/@emotion-unitless-npm-0.10.0-bd15580251-d79346df31.zip differ diff --git a/.yarn/cache/@emotion-utils-npm-1.4.2-2cf43fb561-04cf76849c.zip b/.yarn/cache/@emotion-utils-npm-1.4.2-2cf43fb561-04cf76849c.zip new file mode 100644 index 000000000..b015db750 Binary files /dev/null and b/.yarn/cache/@emotion-utils-npm-1.4.2-2cf43fb561-04cf76849c.zip differ diff --git a/.yarn/cache/@emotion-weak-memoize-npm-0.4.0-76aafb2333-db5da0e89b.zip b/.yarn/cache/@emotion-weak-memoize-npm-0.4.0-76aafb2333-db5da0e89b.zip new file mode 100644 index 000000000..92c932381 Binary files /dev/null and b/.yarn/cache/@emotion-weak-memoize-npm-0.4.0-76aafb2333-db5da0e89b.zip differ diff --git a/.yarn/cache/@esbuild-linux-x64-npm-0.18.20-de8e99b449-8.zip b/.yarn/cache/@esbuild-linux-x64-npm-0.18.20-de8e99b449-8.zip new file mode 100644 index 000000000..bcbc77a84 Binary files /dev/null and b/.yarn/cache/@esbuild-linux-x64-npm-0.18.20-de8e99b449-8.zip differ diff --git a/.yarn/cache/@floating-ui-core-npm-1.6.8-496cdfbb6e-82faa6ea9d.zip b/.yarn/cache/@floating-ui-core-npm-1.6.8-496cdfbb6e-82faa6ea9d.zip new file mode 100644 index 000000000..c8c009dca Binary files /dev/null and b/.yarn/cache/@floating-ui-core-npm-1.6.8-496cdfbb6e-82faa6ea9d.zip differ diff --git a/.yarn/cache/@floating-ui-dom-npm-1.6.12-4d4284e824-956514ed10.zip b/.yarn/cache/@floating-ui-dom-npm-1.6.12-4d4284e824-956514ed10.zip new file mode 100644 index 000000000..67278e9c0 Binary files /dev/null and b/.yarn/cache/@floating-ui-dom-npm-1.6.12-4d4284e824-956514ed10.zip differ diff --git a/.yarn/cache/@floating-ui-react-dom-npm-2.1.2-9e283fcbfa-25bb031686.zip b/.yarn/cache/@floating-ui-react-dom-npm-2.1.2-9e283fcbfa-25bb031686.zip new file mode 100644 index 000000000..7449ee627 Binary files /dev/null and b/.yarn/cache/@floating-ui-react-dom-npm-2.1.2-9e283fcbfa-25bb031686.zip differ diff --git a/.yarn/cache/@floating-ui-utils-npm-0.2.8-01a00634a5-deb98bba01.zip b/.yarn/cache/@floating-ui-utils-npm-0.2.8-01a00634a5-deb98bba01.zip new file mode 100644 index 000000000..fd466226f Binary files /dev/null and b/.yarn/cache/@floating-ui-utils-npm-0.2.8-01a00634a5-deb98bba01.zip differ diff --git a/.yarn/cache/@mui-base-npm-5.0.0-beta.42-ad1681f009-f7af6e6003.zip b/.yarn/cache/@mui-base-npm-5.0.0-beta.42-ad1681f009-f7af6e6003.zip new file mode 100644 index 000000000..fc8bd9215 Binary files /dev/null and b/.yarn/cache/@mui-base-npm-5.0.0-beta.42-ad1681f009-f7af6e6003.zip differ diff --git a/.yarn/cache/@mui-core-downloads-tracker-npm-6.1.8-cda6aa8f67-87e10a0990.zip b/.yarn/cache/@mui-core-downloads-tracker-npm-6.1.8-cda6aa8f67-87e10a0990.zip new file mode 100644 index 000000000..fef46ba08 Binary files /dev/null and b/.yarn/cache/@mui-core-downloads-tracker-npm-6.1.8-cda6aa8f67-87e10a0990.zip differ diff --git a/.yarn/cache/@mui-joy-npm-5.0.0-dev.240424162023-9968b4889d-28d93d935a-79d55a5fe3.zip b/.yarn/cache/@mui-joy-npm-5.0.0-dev.240424162023-9968b4889d-28d93d935a-79d55a5fe3.zip new file mode 100644 index 000000000..30e1baef4 Binary files /dev/null and b/.yarn/cache/@mui-joy-npm-5.0.0-dev.240424162023-9968b4889d-28d93d935a-79d55a5fe3.zip differ diff --git a/.yarn/cache/@mui-private-theming-npm-6.1.8-b2201b1503-1fb22e752b.zip b/.yarn/cache/@mui-private-theming-npm-6.1.8-b2201b1503-1fb22e752b.zip new file mode 100644 index 000000000..65099e474 Binary files /dev/null and b/.yarn/cache/@mui-private-theming-npm-6.1.8-b2201b1503-1fb22e752b.zip differ diff --git a/.yarn/cache/@mui-styled-engine-npm-6.1.8-c1e076ff3d-5d4b222eff.zip b/.yarn/cache/@mui-styled-engine-npm-6.1.8-c1e076ff3d-5d4b222eff.zip new file mode 100644 index 000000000..d1fd6289e Binary files /dev/null and b/.yarn/cache/@mui-styled-engine-npm-6.1.8-c1e076ff3d-5d4b222eff.zip differ diff --git a/.yarn/cache/@mui-system-npm-6.1.8-0211d0c81d-77552807ff.zip b/.yarn/cache/@mui-system-npm-6.1.8-0211d0c81d-77552807ff.zip new file mode 100644 index 000000000..c642cbb2e Binary files /dev/null and b/.yarn/cache/@mui-system-npm-6.1.8-0211d0c81d-77552807ff.zip differ diff --git a/.yarn/cache/@mui-types-npm-7.2.19-d58e375cf9-c3b5723e6f.zip b/.yarn/cache/@mui-types-npm-7.2.19-d58e375cf9-c3b5723e6f.zip new file mode 100644 index 000000000..9d6ee9dd8 Binary files /dev/null and b/.yarn/cache/@mui-types-npm-7.2.19-d58e375cf9-c3b5723e6f.zip differ diff --git a/.yarn/cache/@mui-utils-npm-6.1.8-0eba9ee2ca-68409ea746.zip b/.yarn/cache/@mui-utils-npm-6.1.8-0eba9ee2ca-68409ea746.zip new file mode 100644 index 000000000..2ec6e2baf Binary files /dev/null and b/.yarn/cache/@mui-utils-npm-6.1.8-0eba9ee2ca-68409ea746.zip differ diff --git a/.yarn/cache/@next-swc-linux-x64-gnu-npm-12.3.4-97054948a9-8.zip b/.yarn/cache/@next-swc-linux-x64-gnu-npm-12.3.4-97054948a9-8.zip new file mode 100644 index 000000000..0baaf37df Binary files /dev/null and b/.yarn/cache/@next-swc-linux-x64-gnu-npm-12.3.4-97054948a9-8.zip differ diff --git a/.yarn/cache/@next-swc-linux-x64-gnu-npm-13.5.3-9cf49f8810-8.zip b/.yarn/cache/@next-swc-linux-x64-gnu-npm-13.5.3-9cf49f8810-8.zip new file mode 100644 index 000000000..e6d4814a2 Binary files /dev/null and b/.yarn/cache/@next-swc-linux-x64-gnu-npm-13.5.3-9cf49f8810-8.zip differ diff --git a/.yarn/cache/@swc-core-linux-x64-gnu-npm-1.3.91-d5703afe39-8.zip b/.yarn/cache/@swc-core-linux-x64-gnu-npm-1.3.91-d5703afe39-8.zip new file mode 100644 index 000000000..531b8f035 Binary files /dev/null and b/.yarn/cache/@swc-core-linux-x64-gnu-npm-1.3.91-d5703afe39-8.zip differ diff --git a/.yarn/cache/@types-prop-types-npm-15.7.13-ac81cbe352-8935cad87c.zip b/.yarn/cache/@types-prop-types-npm-15.7.13-ac81cbe352-8935cad87c.zip new file mode 100644 index 000000000..cfe9d1b1e Binary files /dev/null and b/.yarn/cache/@types-prop-types-npm-15.7.13-ac81cbe352-8935cad87c.zip differ diff --git a/README.md b/README.md index d4329fc98..29f110c55 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,10 @@ cp config/localConfig.example.ts config/localConfig.ts ``` sh yarn seed ``` +- Run the command below to update the users' affiliations: + ``` sh + ./node_modules/.bin/ts-node ./server/scripts/updateAllUsersAppAffiliation.ts + ``` ## Build to production - The build step should be run as follow: @@ -88,67 +92,18 @@ Check if users were created successfully by accessing the identities page: ### Ory Cloud #### Taking What You Need: - Create an account and a project on https://console.ory.sh/login. -- Copy the SDK Configuration url and save it. -- Scroll down in the same page and create a Personal Access Tokens, copy the acess token that gonna show up on the bottom of your screen and save it. -- Go to Identity Schema and click on Customize Identity Schema then change the actual schema to the code below and click Update after the change: -``` -{ - "$id": "https://schemas.ory.sh/presets/kratos/identity.email.schema.json", - "title": "Person", - "type": "object", - "properties": { - "traits": { - "type": "object", - "properties": { - "email": { - "type": "string", - "format": "email", - "title": "E-Mail", - "ory.sh/kratos": { - "credentials": { - "password": { - "identifier": true - }, - "webauthn": { - "identifier": true - }, - "totp": { - "account_name": true - } - }, - "recovery": { - "via": "email" - }, - "verification": { - "via": "email" - } - }, - "maxLength": 320 - }, - "user_id": { - "type": "string" - }, - "role": { - "type": "object" - } - }, - "required": [ - "email", - "user_id" - ], - "additionalProperties": false - } - } -} -``` +- In Project settings, copy the SDK configuration URL and save it. +- On the same page, in API keys, create a new API key, copy it, and save it. +- Go to User Management in Identity Schema and click on Duplicate Identity Schema. Then, update the current schema to [IdentitySchema.JSON](https://github.com/AletheiaFact/aletheia/blob/stage/ory_config/identity.schema.json) and click Save after making the changes: - Go to SDK Configuration url that you saved and add /schemas in the end of the url then copy the first id on the page and save it. - If you want to check if it is the right id, at the same url paste after /schemas the / contaning the id that you just copied. #### Making The Changes On Your Code: - First you gonna have to change the ``authentication_type: `` to ory on your config.yaml and config.seed.yaml. - Now take SDK Configuration url and paste on ``url: `` in both pages config.yaml, config.seed.yaml and on ``ORY_SDK_URL=`` in your .env too. -- Now Paste the acess token that you saved on ``access_token: `` in your config.yaml and config.seed.yaml. -- Do the same as above but now with the id that you saved and paste it on ``schema_id: ``. +- Now Paste the acess token that you saved on ``access_token: `` in your config.yaml and config.seed.yaml and on +``ORY_ACCESS_TOKEN=`` in your .env too. +- Do the same as above, but now with the Schema ID you saved, and paste it into ``schema_id`` and on ``ALETHEIA_SCHEMA_ID=`` in .env. #### Setting up your own UI to make the right redirects: - Go to User Interface on Ory Console and rewrite these fields: Login UI with http://localhost:3000/login and Settings UI with http://localhost:3000/profile. diff --git a/package.json b/package.json index 3bf200fa4..d543da1f0 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "@langchain/community": "^0.0.54", "@langchain/openai": "^0.0.28", "@mui/icons-material": "^5.10.9", + "@mui/joy": "^5.0.0-beta.48", "@mui/material": "5.16.6", "@mui/x-data-grid": "^7.12.0", "@nestjs/axios": "^3.0.0", diff --git a/public/locales/en/donationBanner.json b/public/locales/en/donationBanner.json index f83dfb94d..27df9d740 100644 --- a/public/locales/en/donationBanner.json +++ b/public/locales/en/donationBanner.json @@ -1,8 +1,6 @@ { - "title": "AletheiaFact {{date}} Donation Campaign", - "paragraph": "AletheiaFact.org works to combat misinformation and strengthen fact-checking. With your donation, you support the movement against FAKE NEWS, ensuring reliable information reaches you.", - "donateButton": "Donate to aletheia", - "showButton": "Show", - "hideButton": "Hide" - + "title": "AletheiaFact.org needs you to survive", + "paragraph": "AletheiaFact.org is unique and relies on the community. No ads, no subscriptions, we are driven by the passion to ensure free and reliable access to information. With your help, we continue to be a trusted reference. Our strength lies in the community – and that includes you. Today, we ask you to support us in this commitment to the truth. Show Brazil that reliable and impartial information is essential and that you stand with us in this mission. Donate now and help strengthen the fight against misinformation. Even a small donation makes a big difference. This is the time to act so that together, we can promote more democratic journalism and fight misinformation. Thank you for believing in AletheiaFact.org.", + "yesDonateButton": "I want to contribute!", + "noDonateButton": "I don't want to donate" } diff --git a/public/locales/pt/donationBanner.json b/public/locales/pt/donationBanner.json index 0922aaeda..ea445916b 100644 --- a/public/locales/pt/donationBanner.json +++ b/public/locales/pt/donationBanner.json @@ -1,8 +1,6 @@ { - "title": "Campanha doação AletheiaFact {{date}}", - "paragraph": "A AletheiaFact.org trabalha para combater a desinformação e fortalecer a checagem de fatos. Com sua doação, você apoia o movimento contra FAKE NEWS e informações confiáveis cheguem a você.", - "donateButton": "Doe para aletheia", - "showButton": "Mostrar", - "hideButton": "Ocultar" - + "title": "A AletheiaFact.org precisa de você para sobreviver", + "paragraph": "A AletheiaFact.org é única e depende da comunidade. Sem anúncios, sem assinaturas, somos movidos pela paixão de garantir acesso livre e confiável à informação. Com sua ajuda, continuamos sendo um referencial de confiança. Nossa força está na comunidade – e isso inclui você. Hoje, pedimos que nos apoie nesse compromisso com a verdade. Mostre ao Brasil que informações confiáveis e imparciais são essenciais e que você está ao nosso lado nessa missão. Doe agora e ajude a fortalecer o combate à desinformação. Mesmo uma doação pequena faz uma grande diferença. Este é o momento de agir para que, juntos, possamos promover um jornalismo mais democrático e combater a desinformação. Obrigado por acreditar na AletheiaFact.org.", + "yesDonateButton": "Quero contribuir!", + "noDonateButton": "Não quero doar" } diff --git a/server/scripts/createNovuSubscribersFromDB.ts b/server/scripts/createNovuSubscribersFromDB.ts new file mode 100644 index 000000000..3219c80b6 --- /dev/null +++ b/server/scripts/createNovuSubscribersFromDB.ts @@ -0,0 +1,60 @@ +import { NestFactory } from "@nestjs/core"; +import { AppModule } from "../app.module"; +import { NestExpressApplication } from "@nestjs/platform-express"; +import { UsersService } from "../users/users.service"; +import { NotificationService } from "../notifications/notifications.service"; +import { WinstonLogger } from "../winstonLogger"; +import loadConfig from "../configLoader"; + +async function createNovuSubscriber(userFromDB, novuService) { + if (!userFromDB || !userFromDB.id) { + throw new Error(`Invalid user data: ${JSON.stringify(userFromDB)}`); + } + + try { + await novuService.createSubscriber({ + _id: userFromDB.id, + email: userFromDB.email, + name: userFromDB.name, + }); + console.log(`Subscriber created for user ${userFromDB.email}`); + } catch (error) { + throw new Error( + `Failed to create Novu subscriber for user ${userFromDB.email}: ${error.message}` + ); + } +} + +async function initApp() { + const options = loadConfig(); + const logger = new WinstonLogger(); + + const app = await NestFactory.create( + AppModule.register(options) + ); + + logger.log(`AppModule loaded`); + + const userService = await app.resolve(UsersService); + const novuService = await app.resolve(NotificationService); + + try { + const users = await userService.getAllUsers(); + + for (const user of users) { + await createNovuSubscriber(user, novuService); + logger.log(`Novu subscriber created for user: ${user.email}`); + } + + logger.log("All users have been processed for Novu subscription."); + } catch (error) { + logger.error( + "An error occurred while creating Novu subscribers:", + error + ); + } finally { + await app.close(); + } +} + +initApp(); diff --git a/src/components/Home/DonationBanner.style.tsx b/src/components/Home/DonationBanner.style.tsx index 3814ae31c..220fb428a 100644 --- a/src/components/Home/DonationBanner.style.tsx +++ b/src/components/Home/DonationBanner.style.tsx @@ -1,42 +1,45 @@ import styled from "styled-components"; import colors from "../../styles/colors"; import { Col } from "antd"; +import { queries } from "../../styles/mediaQueries"; const DonationBannerStyle = styled(Col)` - background-color: ${colors.quartiary}; + background-color: ${colors.inactive}; - .show-banner { - color: ${colors.white}; - font-size: 13px; - border: none; - background-color: ${colors.blackTertiary}; - font-weight: 600; - cursor: pointer; + .close-banner { + color: ${colors.primary}; + font-size: 25px; align-self: flex-end; position: absolute; right: 10px; - bottom: -25px; + bottom: -10px; z-index: 1; } .banner-content { display: flex; + margin: 25px auto; flex-direction: column; align-items: center; - padding: 20px 0px; + max-width: 60%; + gap: 20px; + } + + .banner-buttons { + display: flex; + gap: 30px; } .banner-content > h1 { width: 100%; - color: ${colors.black}; + color: ${colors.primary}; font-size: 26px; - line-height: 34px; font-weight: 800; text-align: center; } .banner-content > p { - color: ${colors.blackTertiary}; + color: ${colors.black}; font-size: 16px; font-weight: 600; line-height: 24px; @@ -44,7 +47,28 @@ const DonationBannerStyle = styled(Col)` } .banner-button { - font-weight: 600; + font-weight: 700; + } + + @media ${queries.md} { + .banner-content { + max-width: 80%; + } + } + + @media ${queries.xs} { + .banner-content > h1 { + font-size: 20px; + } + + .banner-content > p { + font-size: 12px; + } + + .close-banner { + align-self: flex-start; + top: -10px; + } } `; diff --git a/src/components/Home/DonationBanner.tsx b/src/components/Home/DonationBanner.tsx index b2565379e..a93ac1553 100644 --- a/src/components/Home/DonationBanner.tsx +++ b/src/components/Home/DonationBanner.tsx @@ -1,33 +1,51 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import DonationBannerContent from "./DonationBanner/DonationBannerContent"; import DonationBannerStyle from "./DonationBanner.style"; import { Col } from "antd"; -import { useTranslation } from "next-i18next"; +import Cookies from "js-cookie"; +import CloseOutlined from "@mui/icons-material/CloseOutlined"; + +const closeBanner = (onClose) => { + onClose(); + Cookies.set("cta_donation_banner_show", "false"); +}; const DonationBanner = () => { - const { t } = useTranslation(); - const [isBannerVisible, setIsBannerVisible] = useState(true); - const enableDonationBanner = process.env.NEXT_PUBLIC_ENABLE_BANNER_DONATION === "true"; - const handleToggleBanner = () => { - setIsBannerVisible((prev) => !prev); - } + const enableDonationBanner = + process.env.NEXT_PUBLIC_ENABLE_BANNER_DONATION === "true"; + const [showDonationBanner, setDonationBanner] = useState(false); + + useEffect(() => { + const CloseBannerCookies = Cookies.get("cta_donation_banner_show"); + if (CloseBannerCookies) { + return setDonationBanner(false); + } + setDonationBanner(true); + }, []); - if (!enableDonationBanner){ - return null - }; + if (!enableDonationBanner) { + return null; + } - return ( - - - {isBannerVisible && } - - - - ); + return ( + showDonationBanner && ( + + + + closeBanner(() => setDonationBanner(false)) + } + /> + + closeBanner(() => setDonationBanner(false)) + } + /> + + + ) + ); }; export default DonationBanner; diff --git a/src/components/Home/DonationBanner/DonationBannerButton.tsx b/src/components/Home/DonationBanner/DonationBannerButton.tsx index d0937c9a2..3807db717 100644 --- a/src/components/Home/DonationBanner/DonationBannerButton.tsx +++ b/src/components/Home/DonationBanner/DonationBannerButton.tsx @@ -1,21 +1,34 @@ -import { useTranslation } from "next-i18next"; import Button from "../../Button"; import { trackUmamiEvent } from "../../../lib/umami"; -const DonationBannerButton = ({ type }) => { - const { t } = useTranslation(); +interface DonationBannerButtonProps { + type: any; + closeClick: () => void; + href?: string; + text: string; + trackEvent: string; +} + +const DonationBannerButton = ({ + type, + closeClick, + href, + text, + trackEvent, +}: DonationBannerButtonProps) => { return ( ); }; diff --git a/src/components/Home/DonationBanner/DonationBannerContent.tsx b/src/components/Home/DonationBanner/DonationBannerContent.tsx index e975811ff..8bddba583 100644 --- a/src/components/Home/DonationBanner/DonationBannerContent.tsx +++ b/src/components/Home/DonationBanner/DonationBannerContent.tsx @@ -2,28 +2,35 @@ import React from "react"; import DonationBannerButton from "./DonationBannerButton"; import { ButtonType } from "../../Button"; import { Col } from "antd"; -import { useTranslation } from "next-i18next"; +import { Trans, useTranslation } from "next-i18next"; import DonationBannerStyle from "../DonationBanner.style"; -function DonationBannerContent() { +function DonationBannerContent({ closeClick }) { const { t } = useTranslation(); return ( - - -

- {t("donationBanner:title", { - date: new Date().getFullYear(), - })} -

+ + +

{t("donationBanner:title")}

- {t("donationBanner:paragraph")} +

- +
+ + +
-
- +
); } diff --git a/src/components/topics/TopicForm.tsx b/src/components/topics/TopicForm.tsx index 2b15ad723..7fca6d006 100644 --- a/src/components/topics/TopicForm.tsx +++ b/src/components/topics/TopicForm.tsx @@ -1,12 +1,15 @@ import { Col } from "antd"; import React, { useState } from "react"; import { Controller, useForm } from "react-hook-form"; -import Autocomplete from "../Form/Autocomplete"; +import FormControl from "@mui/joy/FormControl"; +import Autocomplete from "@mui/joy/Autocomplete"; +import CircularProgress from "@mui/joy/CircularProgress"; import AletheiaButton from "../Button"; import TopicInputErrorMessages from "./TopicInputErrorMessages"; import { useTranslation } from "next-i18next"; import TopicsApi from "../../api/topicsApi"; import { ContentModelEnum } from "../../types/enums"; +import { CssVarsProvider } from "@mui/joy/styles"; interface ITopicForm { contentModel: ContentModelEnum; @@ -38,12 +41,24 @@ const TopicForm = ({ reset, } = useForm(); const [isLoading, setIsLoading] = useState(false); + const [options, setOptions] = useState([]); const { t } = useTranslation(); const rules = { required: t("common:requiredFieldError"), validate: { duplicated: (v) => validateDuplication(v) }, }; + const fetchOptions = async (inputValue: string) => { + if (inputValue.length >= 3) { + setIsLoading(true); + const fetchedOptions = await fetchTopicList(inputValue); + setOptions(fetchedOptions); + setIsLoading(false); + } else { + setOptions([]); + } + }; + const handleOnSubmit = async () => { try { setIsLoading(true); @@ -77,48 +92,58 @@ const TopicForm = ({ ); }; - const onSelect = (_value, option) => { - if (option?.label && option?.value) { - setInputValue((prev) => [...prev, option]); - } - }; - - const onDeselect = (_value, option) => { - setInputValue((prev) => - prev.filter(({ value }) => value !== option.value) - ); - }; - return (
( - + rules={{ + validate: validateDuplication, + }} + render={({ field: { onChange, value } }) => ( + + + + fetchOptions(inputValue) + } + onChange={(_, selectedValues) => { + onChange(selectedValues); + setInputValue(selectedValues); + }} + getOptionLabel={(option) => + option.label || "" + } + isOptionEqualToValue={(option, value) => + option.value === value.value + } + loading={isLoading} + endDecorator={ + isLoading ? ( + + ) : null + } + /> + + )} /> {t("topics:addTopicsButton")} diff --git a/yarn.lock b/yarn.lock index 5e2157283..213abddef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2366,6 +2366,15 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:^7.24.4, @babel/runtime@npm:^7.26.0": + version: 7.26.0 + resolution: "@babel/runtime@npm:7.26.0" + dependencies: + regenerator-runtime: ^0.14.0 + checksum: c8e2c0504ab271b3467a261a8f119bf2603eb857a0d71e37791f4e3fae00f681365073cc79f141ddaa90c6077c60ba56448004ad5429d07ac73532be9f7cf28a + languageName: node + linkType: hard + "@babel/template@npm:^7.22.15, @babel/template@npm:^7.22.5, @babel/template@npm:^7.3.3": version: 7.22.15 resolution: "@babel/template@npm:7.22.15" @@ -2660,6 +2669,19 @@ __metadata: languageName: node linkType: hard +"@emotion/cache@npm:^11.13.1": + version: 11.13.5 + resolution: "@emotion/cache@npm:11.13.5" + dependencies: + "@emotion/memoize": ^0.9.0 + "@emotion/sheet": ^1.4.0 + "@emotion/utils": ^1.4.2 + "@emotion/weak-memoize": ^0.4.0 + stylis: 4.2.0 + checksum: d4429bcac07730dd65707b8203f855be3d1958183e05d265eeefbeab19822e70c87250fad9abaeaea575d844256d1b8fee348211ef905f7715234df0ee088188 + languageName: node + linkType: hard + "@emotion/css@npm:^11.10.5, @emotion/css@npm:^11.11.0": version: 11.11.2 resolution: "@emotion/css@npm:11.11.2" @@ -2680,6 +2702,13 @@ __metadata: languageName: node linkType: hard +"@emotion/hash@npm:^0.9.2": + version: 0.9.2 + resolution: "@emotion/hash@npm:0.9.2" + checksum: 379bde2830ccb0328c2617ec009642321c0e009a46aa383dfbe75b679c6aea977ca698c832d225a893901f29d7b3eef0e38cf341f560f6b2b56f1ff23c172387 + languageName: node + linkType: hard + "@emotion/is-prop-valid@npm:^1.1.0, @emotion/is-prop-valid@npm:^1.2.1": version: 1.2.1 resolution: "@emotion/is-prop-valid@npm:1.2.1" @@ -2696,6 +2725,13 @@ __metadata: languageName: node linkType: hard +"@emotion/memoize@npm:^0.9.0": + version: 0.9.0 + resolution: "@emotion/memoize@npm:0.9.0" + checksum: 038132359397348e378c593a773b1148cd0cf0a2285ffd067a0f63447b945f5278860d9de718f906a74c7c940ba1783ac2ca18f1c06a307b01cc0e3944e783b1 + languageName: node + linkType: hard + "@emotion/react@npm:^11.10.4, @emotion/react@npm:^11.11.0, @emotion/react@npm:^11.7.1": version: 11.11.1 resolution: "@emotion/react@npm:11.11.1" @@ -2730,6 +2766,19 @@ __metadata: languageName: node linkType: hard +"@emotion/serialize@npm:^1.3.2": + version: 1.3.3 + resolution: "@emotion/serialize@npm:1.3.3" + dependencies: + "@emotion/hash": ^0.9.2 + "@emotion/memoize": ^0.9.0 + "@emotion/unitless": ^0.10.0 + "@emotion/utils": ^1.4.2 + csstype: ^3.0.2 + checksum: 510331233767ae4e09e925287ca2c7269b320fa1d737ea86db5b3c861a734483ea832394c0c1fe5b21468fe335624a75e72818831d303ba38125f54f44ba02e7 + languageName: node + linkType: hard + "@emotion/sheet@npm:^1.2.2": version: 1.2.2 resolution: "@emotion/sheet@npm:1.2.2" @@ -2737,6 +2786,13 @@ __metadata: languageName: node linkType: hard +"@emotion/sheet@npm:^1.4.0": + version: 1.4.0 + resolution: "@emotion/sheet@npm:1.4.0" + checksum: eeb1212e3289db8e083e72e7e401cd6d1a84deece87e9ce184f7b96b9b5dbd6f070a89057255a6ff14d9865c3ce31f27c39248a053e4cdd875540359042586b4 + languageName: node + linkType: hard + "@emotion/styled@npm:^11.10.4, @emotion/styled@npm:^11.11.0, @emotion/styled@npm:^11.6.0": version: 11.11.0 resolution: "@emotion/styled@npm:11.11.0" @@ -2764,6 +2820,13 @@ __metadata: languageName: node linkType: hard +"@emotion/unitless@npm:^0.10.0": + version: 0.10.0 + resolution: "@emotion/unitless@npm:0.10.0" + checksum: d79346df31a933e6d33518e92636afeb603ce043f3857d0a39a2ac78a09ef0be8bedff40130930cb25df1beeee12d96ee38613963886fa377c681a89970b787c + languageName: node + linkType: hard + "@emotion/unitless@npm:^0.7.4": version: 0.7.5 resolution: "@emotion/unitless@npm:0.7.5" @@ -2794,6 +2857,13 @@ __metadata: languageName: node linkType: hard +"@emotion/utils@npm:^1.4.2": + version: 1.4.2 + resolution: "@emotion/utils@npm:1.4.2" + checksum: 04cf76849c6401205c058b82689fd0ec5bf501aed6974880fe9681a1d61543efb97e848f4c38664ac4a9068c7ad2d1cb84f73bde6cf95f1208aa3c28e0190321 + languageName: node + linkType: hard + "@emotion/weak-memoize@npm:^0.3.1": version: 0.3.1 resolution: "@emotion/weak-memoize@npm:0.3.1" @@ -2801,6 +2871,13 @@ __metadata: languageName: node linkType: hard +"@emotion/weak-memoize@npm:^0.4.0": + version: 0.4.0 + resolution: "@emotion/weak-memoize@npm:0.4.0" + checksum: db5da0e89bd752c78b6bd65a1e56231f0abebe2f71c0bd8fc47dff96408f7065b02e214080f99924f6a3bfe7ee15afc48dad999d76df86b39b16e513f7a94f52 + languageName: node + linkType: hard + "@esbuild/android-arm64@npm:0.18.20": version: 0.18.20 resolution: "@esbuild/android-arm64@npm:0.18.20" @@ -2982,6 +3059,25 @@ __metadata: languageName: node linkType: hard +"@floating-ui/core@npm:^1.6.0": + version: 1.6.8 + resolution: "@floating-ui/core@npm:1.6.8" + dependencies: + "@floating-ui/utils": ^0.2.8 + checksum: 82faa6ea9d57e466779324e51308d6d49c098fb9d184a08d9bb7f4fad83f08cc070fc491f8d56f0cad44a16215fb43f9f829524288413e6c33afcb17303698de + languageName: node + linkType: hard + +"@floating-ui/dom@npm:^1.0.0": + version: 1.6.12 + resolution: "@floating-ui/dom@npm:1.6.12" + dependencies: + "@floating-ui/core": ^1.6.0 + "@floating-ui/utils": ^0.2.8 + checksum: 956514ed100c0c853e73ace9e3c877b7e535444d7c31326f687a7690d49cb1e59ef457e9c93b76141aea0d280e83ed5a983bb852718b62eea581f755454660f6 + languageName: node + linkType: hard + "@floating-ui/dom@npm:^1.2.1, @floating-ui/dom@npm:^1.5.1": version: 1.5.3 resolution: "@floating-ui/dom@npm:1.5.3" @@ -3016,6 +3112,18 @@ __metadata: languageName: node linkType: hard +"@floating-ui/react-dom@npm:^2.0.8": + version: 2.1.2 + resolution: "@floating-ui/react-dom@npm:2.1.2" + dependencies: + "@floating-ui/dom": ^1.0.0 + peerDependencies: + react: ">=16.8.0" + react-dom: ">=16.8.0" + checksum: 25bb031686e23062ed4222a8946e76b3f9021d40a48437bd747233c4964a766204b8a55f34fa8b259839af96e60db7c6e3714d81f1de06914294f90e86ffbc48 + languageName: node + linkType: hard + "@floating-ui/react@npm:^0.19.1": version: 0.19.2 resolution: "@floating-ui/react@npm:0.19.2" @@ -3051,6 +3159,13 @@ __metadata: languageName: node linkType: hard +"@floating-ui/utils@npm:^0.2.8": + version: 0.2.8 + resolution: "@floating-ui/utils@npm:0.2.8" + checksum: deb98bba017c4e073c7ad5740d4dec33a4d3e0942d412e677ac0504f3dade15a68fc6fd164d43c93c0bb0bcc5dc5015c1f4080dfb1a6161140fe660624f7c875 + languageName: node + linkType: hard + "@foliojs-fork/fontkit@npm:^1.9.1": version: 1.9.1 resolution: "@foliojs-fork/fontkit@npm:1.9.1" @@ -4025,6 +4140,28 @@ __metadata: languageName: node linkType: hard +"@mui/base@npm:5.0.0-beta.42": + version: 5.0.0-beta.42 + resolution: "@mui/base@npm:5.0.0-beta.42" + dependencies: + "@babel/runtime": ^7.24.4 + "@floating-ui/react-dom": ^2.0.8 + "@mui/types": ^7.2.14 + "@mui/utils": ^6.0.0-alpha.1 + "@popperjs/core": ^2.11.8 + clsx: ^2.1.0 + prop-types: ^15.8.1 + peerDependencies: + "@types/react": ^17.0.0 || ^18.0.0 + react: ^17.0.0 || ^18.0.0 + react-dom: ^17.0.0 || ^18.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + checksum: f7af6e6003a4a8502062607b7861490eb6dc3a1f617532c92521981329ae077535444d65e378718bbf59ce8b7a52fc32275dc794969c73bdb389e5d69155fc69 + languageName: node + linkType: hard + "@mui/core-downloads-tracker@npm:^5.14.11": version: 5.14.11 resolution: "@mui/core-downloads-tracker@npm:5.14.11" @@ -4039,6 +4176,13 @@ __metadata: languageName: node linkType: hard +"@mui/core-downloads-tracker@npm:^6.0.0-dev.240424162023-9968b4889d": + version: 6.1.8 + resolution: "@mui/core-downloads-tracker@npm:6.1.8" + checksum: 87e10a09909d32f9a1618fe23d5f7bf8981a942431be3432ae5cb24c31502af93eca38204e46619a3546f13a5c32b1741c80f24657a29a6e7a9e53d4384d042d + languageName: node + linkType: hard + "@mui/icons-material@npm:^5.10.9": version: 5.14.11 resolution: "@mui/icons-material@npm:5.14.11" @@ -4055,6 +4199,35 @@ __metadata: languageName: node linkType: hard +"@mui/joy@npm:^5.0.0-beta.48": + version: 5.0.0-dev.240424162023-9968b4889d + resolution: "@mui/joy@npm:5.0.0-dev.240424162023-9968b4889d" + dependencies: + "@babel/runtime": ^7.24.4 + "@mui/base": 5.0.0-beta.42 + "@mui/core-downloads-tracker": ^6.0.0-dev.240424162023-9968b4889d + "@mui/system": ^6.0.0-dev.240424162023-9968b4889d + "@mui/types": ^7.2.14 + "@mui/utils": ^6.0.0-alpha.3 + clsx: ^2.1.0 + prop-types: ^15.8.1 + peerDependencies: + "@emotion/react": ^11.5.0 + "@emotion/styled": ^11.3.0 + "@types/react": ^17.0.0 || ^18.0.0 + react: ^17.0.0 || ^18.0.0 + react-dom: ^17.0.0 || ^18.0.0 + peerDependenciesMeta: + "@emotion/react": + optional: true + "@emotion/styled": + optional: true + "@types/react": + optional: true + checksum: 79d55a5fe3da89c349f64ce755420f0ecd52bcb0feff2f1b4b3034a8879d68ba06855285d4a869076de382342f6a1ee267657356409c284168fd1593303bab8c + languageName: node + linkType: hard + "@mui/material@npm:5.16.6": version: 5.16.6 resolution: "@mui/material@npm:5.16.6" @@ -4155,6 +4328,23 @@ __metadata: languageName: node linkType: hard +"@mui/private-theming@npm:^6.1.8": + version: 6.1.8 + resolution: "@mui/private-theming@npm:6.1.8" + dependencies: + "@babel/runtime": ^7.26.0 + "@mui/utils": ^6.1.8 + prop-types: ^15.8.1 + peerDependencies: + "@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0 + react: ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + checksum: 1fb22e752b7d44bc0879c2cd74195181d41eaae802a64d5ae3df3e33fea5bb6cb8708778fff6857190940cd1a673e303fde457d99f30cc3d184f5bcf772c7ac9 + languageName: node + linkType: hard + "@mui/styled-engine@npm:^5.14.11": version: 5.14.11 resolution: "@mui/styled-engine@npm:5.14.11" @@ -4197,6 +4387,29 @@ __metadata: languageName: node linkType: hard +"@mui/styled-engine@npm:^6.1.8": + version: 6.1.8 + resolution: "@mui/styled-engine@npm:6.1.8" + dependencies: + "@babel/runtime": ^7.26.0 + "@emotion/cache": ^11.13.1 + "@emotion/serialize": ^1.3.2 + "@emotion/sheet": ^1.4.0 + csstype: ^3.1.3 + prop-types: ^15.8.1 + peerDependencies: + "@emotion/react": ^11.4.1 + "@emotion/styled": ^11.3.0 + react: ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + "@emotion/react": + optional: true + "@emotion/styled": + optional: true + checksum: 5d4b222effd851b3db035656bb9c032d25847a258e5af87dd52e8f4213fc8f9ce51521f6384a2ad4b6909342d29cb6e0341a9d4362c2c3b820144d59c0766dcb + languageName: node + linkType: hard + "@mui/system@npm:^5.13.2": version: 5.16.7 resolution: "@mui/system@npm:5.16.7" @@ -4281,6 +4494,46 @@ __metadata: languageName: node linkType: hard +"@mui/system@npm:^6.0.0-dev.240424162023-9968b4889d": + version: 6.1.8 + resolution: "@mui/system@npm:6.1.8" + dependencies: + "@babel/runtime": ^7.26.0 + "@mui/private-theming": ^6.1.8 + "@mui/styled-engine": ^6.1.8 + "@mui/types": ^7.2.19 + "@mui/utils": ^6.1.8 + clsx: ^2.1.1 + csstype: ^3.1.3 + prop-types: ^15.8.1 + peerDependencies: + "@emotion/react": ^11.5.0 + "@emotion/styled": ^11.3.0 + "@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0 + react: ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + "@emotion/react": + optional: true + "@emotion/styled": + optional: true + "@types/react": + optional: true + checksum: 77552807ff81065eebcc3b5451e358b82e79ff3c0b4720f3dc5b98b28ffd69885dbb0fc1e17bc2800cc36720fd050a38c6545bec899f6349dc8aabc00929cd24 + languageName: node + linkType: hard + +"@mui/types@npm:^7.2.14, @mui/types@npm:^7.2.19": + version: 7.2.19 + resolution: "@mui/types@npm:7.2.19" + peerDependencies: + "@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + checksum: c3b5723e6f0861d47df834c57878f19347aefecdaf948cf9a25a64b73fbc75791430693d0f540b2bdc01bdfc605dc32bf4ba738113ec415aa9eaf002ce38f064 + languageName: node + linkType: hard + "@mui/types@npm:^7.2.15": version: 7.2.15 resolution: "@mui/types@npm:7.2.15" @@ -4343,6 +4596,26 @@ __metadata: languageName: node linkType: hard +"@mui/utils@npm:^6.0.0-alpha.1, @mui/utils@npm:^6.0.0-alpha.3, @mui/utils@npm:^6.1.8": + version: 6.1.8 + resolution: "@mui/utils@npm:6.1.8" + dependencies: + "@babel/runtime": ^7.26.0 + "@mui/types": ^7.2.19 + "@types/prop-types": ^15.7.13 + clsx: ^2.1.1 + prop-types: ^15.8.1 + react-is: ^18.3.1 + peerDependencies: + "@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0 + react: ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + "@types/react": + optional: true + checksum: 68409ea7463a5961ee6ef2f87fc794f194d3711f23e8fec8651e78c28cfdb07b244abe46c8c45415eeaf244a479c10c5472fcea28c3500bdd6db7fae1c4f42a6 + languageName: node + linkType: hard + "@mui/x-data-grid@npm:^7.12.0": version: 7.12.0 resolution: "@mui/x-data-grid@npm:7.12.0" @@ -9924,6 +10197,13 @@ __metadata: languageName: node linkType: hard +"@types/prop-types@npm:^15.7.13": + version: 15.7.13 + resolution: "@types/prop-types@npm:15.7.13" + checksum: 8935cad87c683c665d09a055919d617fe951cb3b2d5c00544e3a913f861a2bd8d2145b51c9aa6d2457d19f3107ab40784c40205e757232f6a80cc8b1c815513c + languageName: node + linkType: hard + "@types/qs@npm:*, @types/qs@npm:^6.9.5": version: 6.9.8 resolution: "@types/qs@npm:6.9.8" @@ -11114,6 +11394,7 @@ __metadata: "@langchain/community": ^0.0.54 "@langchain/openai": ^0.0.28 "@mui/icons-material": ^5.10.9 + "@mui/joy": ^5.0.0-beta.48 "@mui/material": 5.16.6 "@mui/x-data-grid": ^7.12.0 "@nestjs/axios": ^3.0.0