Skip to content

Commit

Permalink
[support] #68
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Jul 22, 2021
1 parent 7313455 commit 30af19d
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 23 deletions.
22 changes: 22 additions & 0 deletions src/api/Mail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import axios from "axios";
import {restfulApiConfig} from "./Config";
import {MailSendData} from "../interface";

export function Post(data: MailSendData): Promise<{ error: string; data: any }> {
return axios.post(restfulApiConfig.apiURL + "/mail", data, {
headers: {
'Content-Type': 'application/json',
ACCESS_TOKEN: sessionStorage.getItem('AccessToken'),
}
}).then(res => {
return {
error: "",
data: res.data
};
}).catch(err => {
return {
error: "[" + err.response.status + "] " + err.response.data.error,
data: null
};
})
}
19 changes: 19 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ export interface NTTTemplateData {
hidden: boolean
}

export interface MailTemplateData {
process_id: string
subject: string
message: string
}

export interface IPTemplateData {
name: any;
CreatedAt: string
Expand Down Expand Up @@ -380,6 +386,7 @@ export interface TemplateData {
ipv6_route?: IPRouteData[]
user?: UserDetailData[]
group?: GroupDetailData[]
mail_template?: MailTemplateData[]
}

export interface IPRouteData {
Expand Down Expand Up @@ -478,6 +485,12 @@ export interface ChatData {
admin: boolean,
}

export interface MailSendData {
to_mail: string,
subject: string,
content: string,
}

export const DefaultTemplateData: TemplateData = {
bgp_router: undefined,
connections: undefined,
Expand Down Expand Up @@ -817,4 +830,10 @@ export const DefaultTicketAddData: TicketAddData = {
group_id: 0,
title: "",
data: ""
}

export const DefaultMailSendData: MailSendData = {
to_mail: "",
subject: "",
content: ""
}
33 changes: 21 additions & 12 deletions src/pages/Group/GroupDetail/Connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ export function RowConnectionCheck(props: {
<TableBody>
{
service.connections.map((rowConnection: ConnectionDetailData) => (
<RowConnection key={rowConnection.ID}
template={template}
service={service}
connection={rowConnection}
groupID={groupID}
reload={reload}
<RowConnection
key={rowConnection.ID}
template={template}
service={service}
connection={rowConnection}
groupID={groupID}
reload={reload}
/>
))
}
Expand Down Expand Up @@ -118,14 +119,22 @@ function RowConnection(props: {
</TableCell>
<TableCell align="right">
<Box display="flex" justifyContent="flex-end">
<ConnectionGetDialogs key={"connection_get_dialog"} connection={connection} service={service}
template={template} reload={reload}/>
<ConnectionGetDialogs
key={"connection_get_dialog"}
connection={connection}
service={service}
template={template}
reload={reload}/>
&nbsp;
<DeleteDialog key={"connection_delete_alert_dialog_" + connection.ID} id={connection.ID}
reload={reload}/>
<DeleteDialog
key={"connection_delete_alert_dialog_" + connection.ID}
id={connection.ID}
reload={reload}/>
&nbsp;
<EnableDialog key={"connection_enable_alert_dialog_" + connection.ID} connection={connection}
reload={reload}/>
<EnableDialog
key={"connection_enable_alert_dialog_" + connection.ID}
connection={connection}
reload={reload}/>
</Box>
</TableCell>
</TableRow>
Expand Down
15 changes: 10 additions & 5 deletions src/pages/Group/GroupDetail/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ function ChipAgree(props: { agree: boolean }) {
export function GroupProfileInfo(props: {
data: GroupDetailData,
template: TemplateData,
setOpenMailSendDialog: Dispatch<SetStateAction<boolean>>
setReload: Dispatch<SetStateAction<boolean>>
}): any {
const {data, template, setReload} = props;
const {data, template, setOpenMailSendDialog, setReload} = props;
const classes = useStyles();
const [lockPersonalInformation, setLockPersonalInformation] = React.useState(true);
const [group, setGroup] = useState(data);
Expand Down Expand Up @@ -395,7 +396,7 @@ export function GroupProfileInfo(props: {
接続情報の追加
</Button>
<br/>
<Button size="small" className={classes.spaceTop}>メール送信</Button>
<Button size="small" className={classes.spaceTop} onClick={() => setOpenMailSendDialog(true)}>メール送信</Button>
<ServiceAddDialogs
key={"service_add_dialogs"}
baseData={data}
Expand All @@ -417,15 +418,19 @@ export function GroupProfileInfo(props: {
)
}

export function GroupMainMenu(props: { data: GroupDetailData, reload: Dispatch<SetStateAction<boolean>> }): any {
export function GroupMainMenu(props: {
data: GroupDetailData,
autoMail: Dispatch<SetStateAction<string>>,
reload: Dispatch<SetStateAction<boolean>>
}): any {
const classes = useStyles();
const {data, reload} = props;
const {data, autoMail, reload} = props;

return (
<Card className={classes.root}>
<CardContent>
<h3>Menu</h3>
<GroupStatusButton key={"group_status_button"} data={data} reload={reload}/>
<GroupStatusButton key={"group_status_button"} data={data} autoMail={autoMail} reload={reload}/>
<GroupLockButton key={"group_lock_button"} data={data} reload={reload}/>
<GroupAbolition key={"group_abolition"}/>
</CardContent>
Expand Down
41 changes: 39 additions & 2 deletions src/pages/Group/GroupDetail/GroupDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Service from "./Service";
import {GroupProfileInfo, GroupMainMenu, GroupStatus} from "./Group";
import {useSnackbar} from "notistack";
import {GroupMemo} from "./Memo";
import {MailAutoSendDialogs, MailSendDialogs} from "../Mail";


function getTitle(id: number, org: string, org_en: string, loading: boolean): string {
Expand All @@ -33,6 +34,9 @@ export default function GroupDetail() {
const [loading, setLoading] = useState(true)
const [group, setGroup] = useState(DefaultGroupDetailData);
const [template, setTemplate] = useState(DefaultTemplateData);
const [openMailSendDialog, setOpenMailSendDialog] = useState(false);
const [openMailAutoSendDialog, setOpenMailAutoSendDialog] = useState("");
const [sendAutoEmail, setSendAutoEmail] = useState("");
let id: string;
({id} = useParams());

Expand All @@ -54,6 +58,15 @@ export default function GroupDetail() {
if (res.error === "") {
console.log(res);
setGroup(res.data);
let mails = "";
if (res.data.users != undefined) {
for (const user of res.data.users) {
if (user.level < 3) {
mails += user.email + ",";
}
}
}
setSendAutoEmail(mails);
setLoading(false);
setReload(false);
} else {
Expand Down Expand Up @@ -89,7 +102,11 @@ export default function GroupDetail() {
<GroupStatus key={"group_status_" + group.ID} data={group} reload={reload}/>
</Grid>
<Grid item xs={2}>
<GroupMainMenu key={"group_main_menu" + group.ID} data={group} reload={setReload}/>
<GroupMainMenu
key={"group_main_menu" + group.ID}
data={group}
autoMail={setOpenMailAutoSendDialog}
reload={setReload}/>
</Grid>
<Grid item xs={3}>
<GroupMemo key={"group_memo_" + group.ID} data={group} reload={setReload}/>
Expand All @@ -98,12 +115,17 @@ export default function GroupDetail() {
<GroupProfileInfo
key={"group_profile_info_" + group.ID}
data={group}
setOpenMailSendDialog={setOpenMailSendDialog}
template={template}
setReload={setReload}
/>
</Grid>
<Grid item xs={12}>
<Service key={"service_" + group.ID} data={group} template={template} reload={setReload}/>
<Service
key={"service_" + group.ID}
data={group}
template={template}
reload={setReload}/>
</Grid>
<Grid item xs={12}>
<Ticket key={"ticket_" + group.ID} data={group.tickets} setReload={setReload}/>
Expand All @@ -114,6 +136,21 @@ export default function GroupDetail() {
<Grid item xs={6}>
<Users key={"users_" + group.ID} data={group}/>
</Grid>
<Grid item xs={12}>
<MailAutoSendDialogs
setOpen={setOpenMailAutoSendDialog}
mails={sendAutoEmail}
template={template?.mail_template}
open={openMailAutoSendDialog}
org={group.org}
/>
<MailSendDialogs
setOpen={setOpenMailSendDialog}
open={openMailSendDialog}
mails={sendAutoEmail}
template={template?.mail_template}
org={group.org}/>
</Grid>
</Grid>
)
}
Expand Down
12 changes: 10 additions & 2 deletions src/pages/Group/GroupDetail/GroupMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import useStyles from "./styles";
import {Put} from "../../../api/Group";
import {useSnackbar} from "notistack";

export function GroupStatusButton(props: { data: GroupDetailData, reload: Dispatch<SetStateAction<boolean>> }): any {
const {data, reload} = props;
export function GroupStatusButton(props: {
data: GroupDetailData,
autoMail: Dispatch<SetStateAction<string>>,
reload: Dispatch<SetStateAction<boolean>>
}): any {
const {data, autoMail, reload} = props;
const classes = useStyles();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);

Expand All @@ -23,6 +27,10 @@ export function GroupStatusButton(props: { data: GroupDetailData, reload: Dispat
console.log(res.error);
}

if (pass) {
autoMail("pass_the_examination");
}

handleClose();
reload(true);
})
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Group/GroupDetail/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,12 @@ export default function Service(props: {
<TableBody>
{
data.services.map((row: ServiceDetailData) => (
<RowService key={"service_row_service_" + row.ID} template={template}
service={row} groupID={data.ID} reload={reload}/>
<RowService
key={"service_row_service_" + row.ID}
template={template}
service={row}
groupID={data.ID}
reload={reload}/>
))
}
</TableBody>
Expand Down
Loading

0 comments on commit 30af19d

Please sign in to comment.