Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add listing email response using notify button #155

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions apps/app/components/FeedbackModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Input, Modal, Tabs } from "antd";
import React, { useEffect, useState } from "react";

interface TabInfo {
tabTitle: string;
info: string;
}

interface DynamicTabsProps {
visible: boolean;
onClose: () => void;
tabsInfo: TabInfo[];
modalTitle: string;
}

const FeedbackModal: React.FC<DynamicTabsProps> = ({
visible,
onClose,
tabsInfo,
modalTitle,
}) => {
const [activeTab, setActiveTab] = useState<string>("");
const [tabInfo, setTabInfo] = useState<string>("");

useEffect(() => {
if (tabsInfo.length > 0) {
setActiveTab(tabsInfo[0].tabTitle);
setTabInfo(tabsInfo[0].info);
}
}, [tabsInfo]);

const handleTabChange = (key: string) => {
const selectedTab = tabsInfo.find((tab) => tab.tabTitle === key);
if (selectedTab) {
setActiveTab(selectedTab.tabTitle);
setTabInfo(selectedTab.info);
}
};

return (
<Modal
title={modalTitle}
visible={visible}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
visible={visible}
open={visible}

visible is deprecated which will be removed in next the major version of AntDesign. Use open instead 🙏🏻

onCancel={onClose}
footer={null}
>
<Tabs activeKey={activeTab} onChange={handleTabChange}>
{tabsInfo.map((tab) => (
<Tabs.TabPane tab={tab.tabTitle} key={tab.tabTitle}>
<Input.TextArea
value={tabInfo}
rows={25}
style={{ resize: "none" }}
placeholder="Nenhuma informação para apresentar"
readOnly={true}
/>
</Tabs.TabPane>
))}
</Tabs>
</Modal>
);
};

export default FeedbackModal;
61 changes: 54 additions & 7 deletions apps/app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { Button, Col, Popconfirm, Row, Typography } from "antd";
import { Button, Col, Modal, Popconfirm, Row, Typography } from "antd";
import { useAuth } from "@coderdojobraga/ui";
import { withAuth } from "~/components/Auth/withAuth";
import AppLayout from "~/layouts/AppLayout";
Expand All @@ -9,6 +9,7 @@ import { EUser, getNinjas, notify_selected, notify_signup } from "bokkenjs";
import Ninja from "~/components/Ninja";
import { useEvents } from "~/hooks/events";
import { notifyError, notifyInfo } from "~/components/Notification";
import FeedbackModal from "~/components/FeedbackModal";
import styles from "~/styles/Dashboard.module.css";
import moment from "moment";

Expand All @@ -34,10 +35,34 @@ function Dashboard() {
return sorted_events[0] != undefined ? sorted_events[0] : false;
};

const [modalVisible, setModalVisible] = useState(false);

const openModal = () => {
setModalVisible(true);
};

const closeModal = () => {
setModalVisible(false);
};

const [tabsInfo, setTabsInfo] = useState([
{ tabTitle: "None", info: "Sem informação" },
]);

const notify_signup_ninjas = () => {
notify_signup()
.then(() => {
notifyInfo("Enviado com sucesso!");
.then((response) => {
setTabsInfo((prevTabsInfo) => [
{
tabTitle: "Enviados",
info: response.success,
},
{
tabTitle: "Não enviados",
info: response.fail,
},
]);
notifyInfo("Enviado com successo!");
})
.catch((error) => {
notifyError("Não foi enviado!");
Expand All @@ -46,8 +71,18 @@ function Dashboard() {

const notify_selected_ninjas = () => {
notify_selected()
.then(() => {
notifyInfo("Enviado com sucesso!");
.then((response) => {
setTabsInfo((prevTabsInfo) => [
{
tabTitle: "Enviados",
info: response.success,
},
{
tabTitle: "Não enviados",
info: response.fail,
},
]);
notifyInfo("Enviado com successo!");
})
.catch((error) => {
notifyError("Não foi enviado!");
Expand Down Expand Up @@ -80,7 +115,10 @@ function Dashboard() {
title="Tens a certeza que queres notificar?"
cancelText="Não"
okText="Sim"
onConfirm={(_) => notify_signup_ninjas()}
onConfirm={(_) => {
notify_signup_ninjas();
openModal();
}}
>
<Button type="primary">Notificar abertura</Button>
</Popconfirm>
Expand All @@ -94,7 +132,10 @@ function Dashboard() {
title="Tens a certeza que queres notificar?"
cancelText="Não"
okText="Sim"
onConfirm={(_) => notify_selected_ninjas()}
onConfirm={(_) => {
notify_selected_ninjas();
openModal();
}}
>
<Button type="primary">Notificar selecionados</Button>
</Popconfirm>
Expand Down Expand Up @@ -149,6 +190,12 @@ function Dashboard() {
<></>
)}
</AppLayout>
<FeedbackModal
visible={modalVisible}
onClose={closeModal}
tabsInfo={tabsInfo}
modalTitle="Relatório de e-mails"
/>
</>
);
}
Expand Down