diff --git a/backend/src/services/QuickMessageService/FindService.ts b/backend/src/services/QuickMessageService/FindService.ts index 4866ac1a..84ccc571 100644 --- a/backend/src/services/QuickMessageService/FindService.ts +++ b/backend/src/services/QuickMessageService/FindService.ts @@ -1,18 +1,31 @@ import { Op } from "sequelize"; import QuickMessage from "../../models/QuickMessage"; import Company from "../../models/Company"; +import CheckSettings from "../../helpers/CheckSettings"; type Params = { companyId: string; userId: string; }; +type QuickMessageWhere = { + companyId: string; + userId?: string; +} + const FindService = async ({ companyId, userId }: Params): Promise => { + const where: QuickMessageWhere = { + companyId, + } + + const quickMessagesSetting = await CheckSettings("quickMessages","individual"); + + if (quickMessagesSetting === "individual") { + where.userId = userId + } + const notes: QuickMessage[] = await QuickMessage.findAll({ - where: { - companyId, - userId, - }, + where, include: [{ model: Company, as: "company", attributes: ["id", "name"] }], order: [["shortcode", "ASC"]] }); diff --git a/frontend/src/components/Settings/Options.js b/frontend/src/components/Settings/Options.js index a5a72db3..66b1b8e3 100644 --- a/frontend/src/components/Settings/Options.js +++ b/frontend/src/components/Settings/Options.js @@ -86,6 +86,7 @@ export default function Options(props) { const [scheduleType, setScheduleType] = useState("disabled"); const [callType, setCallType] = useState("enabled"); const [chatbotType, setChatbotType] = useState(""); + const [quickMessages, setQuickMessages] = useState(""); const [allowSignup, setAllowSignup] = useState("disabled"); const [CheckMsgIsGroup, setCheckMsgIsGroupType] = useState("enabled"); @@ -93,6 +94,7 @@ export default function Options(props) { const [loadingScheduleType, setLoadingScheduleType] = useState(false); const [loadingCallType, setLoadingCallType] = useState(false); const [loadingChatbotType, setLoadingChatbotType] = useState(false); + const [loadingQuickMessages, setLoadingQuickMessages] = useState(false); const [loadingAllowSignup, setLoadingAllowSignup] = useState(false); const [loadingCheckMsgIsGroup, setCheckMsgIsGroup] = useState(false); const { getCurrentUserInfo } = useAuth(); @@ -132,6 +134,8 @@ export default function Options(props) { if (allowSignup) { setAllowSignup(allowSignup.value); } + const quickMessages = settings.find((s) => s.key === "quickMessages"); + setQuickMessages(quickMessages?.value || "individual"); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [settings]); @@ -192,6 +196,17 @@ export default function Options(props) { setLoadingChatbotType(false); } + async function handleQuickMessages(value) { + setQuickMessages(value); + setLoadingQuickMessages(true); + await update({ + key: "quickMessages", + value, + }); + toast.success("Operação atualizada com sucesso."); + setLoadingQuickMessages(false); + } + async function handleAllowSignup(value) { setAllowSignup(value); setLoadingAllowSignup(true); @@ -321,6 +336,26 @@ export default function Options(props) { + + + + Mensagens Rápidas + + + + {loadingQuickMessages && "Atualizando..."} + + + (