Skip to content

Commit

Permalink
Allow company-wide quick messages - fix #28
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Jun 13, 2024
1 parent 72e838f commit 6663748
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
21 changes: 17 additions & 4 deletions backend/src/services/QuickMessageService/FindService.ts
Original file line number Diff line number Diff line change
@@ -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<QuickMessage[]> => {
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"]]
});
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/components/Settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ 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");

const [loadingUserRating, setLoadingUserRating] = useState(false);
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();
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -321,6 +336,26 @@ export default function Options(props) {
</FormHelperText>
</FormControl>
</Grid>
<Grid xs={12} sm={6} md={4} item>
<FormControl className={classes.selectContainer}>
<InputLabel id="quickmessages-label">
Mensagens Rápidas
</InputLabel>
<Select
labelId="quickmessages-label"
value={quickMessages}
onChange={async (e) => {
handleQuickMessages(e.target.value);
}}
>
<MenuItem value={"company"}>Por empresa</MenuItem>
<MenuItem value={"individual"}>Por usuário</MenuItem>
</Select>
<FormHelperText>
{loadingQuickMessages && "Atualizando..."}
</FormHelperText>
</FormControl>
</Grid>
<OnlyForSuperUser
user={currentUser}
yes={() => (
Expand Down

0 comments on commit 6663748

Please sign in to comment.