diff --git a/components/display-notices.js b/components/display-notices.js index 8bd38d3..4733379 100644 --- a/components/display-notices.js +++ b/components/display-notices.js @@ -291,8 +291,20 @@ const DataDisplay = (props) => { ) })} + {detail.intranet ? ( +
+ Intranet +
+ ) : ( + + )} -
Uploaded By : {detail.email}
Updated By: {detail.updatedBy}
diff --git a/components/notices-props/add-form.js b/components/notices-props/add-form.js index d6dcb3e..9323bb7 100644 --- a/components/notices-props/add-form.js +++ b/components/notices-props/add-form.js @@ -27,6 +27,7 @@ export const AddForm = ({ handleClose, modal }) => { department: '', isVisible: true, important: false, + intranet: false, notice_type: 'department', }) @@ -44,7 +45,11 @@ export const AddForm = ({ handleClose, modal }) => { const [submitting, setSubmitting] = useState(false) const handleChange = (e) => { - if (e.target.name == 'important' || e.target.name == 'isVisible') { + if ( + e.target.name == 'important' || + e.target.name == 'isVisible' || + e.target.name == 'intranet' + ) { setContent({ ...content, [e.target.name]: e.target.checked }) } else { setContent({ ...content, [e.target.name]: e.target.value }) @@ -66,6 +71,7 @@ export const AddForm = ({ handleClose, modal }) => { id: now, isVisible: content.isVisible ? 1 : 0, important: content.important ? 1 : 0, + intranet: content.intranet ? 1 : 0, notice_type: session.user.role == 4 ? session.user.administration @@ -218,6 +224,16 @@ export const AddForm = ({ handleClose, modal }) => { } label="Visibility" /> + handleChange(e)} + /> + } + label="Intranet" + /> { notice_type: data.notice_type, isVisible: data.isVisible ? true : false, important: data.important ? true : false, + intranet: data.intranet ? true : false, }) const [verifyDelete, setVerifyDelete] = useState(false) @@ -52,7 +53,11 @@ export const EditForm = ({ data, handleClose, modal }) => { const [newMainAttachment, setNewMainAttachment] = useState({}) const handleChange = (e) => { - if (e.target.name == 'important' || e.target.name == 'isVisible') { + if ( + e.target.name == 'important' || + e.target.name == 'isVisible' || + e.target.name == 'intranet' + ) { setContent({ ...content, [e.target.name]: e.target.checked }) } else { setContent({ ...content, [e.target.name]: e.target.value }) @@ -104,6 +109,7 @@ export const EditForm = ({ data, handleClose, modal }) => { isVisible: content.isVisible ? 1 : 0, important: content.important ? 1 : 0, + intranet: content.intranet ? 1 : 0, openDate: open, closeDate: close, timestamp: now, @@ -244,6 +250,16 @@ export const EditForm = ({ data, handleClose, modal }) => { } label="Visibility" /> + handleChange(e)} + /> + } + label="Intranet" + /> { ) params.timestamp = new Date().getTime() let result = await query( - `INSERT INTO notices (id,title,timestamp,openDate,closeDate,important,attachments,email,isVisible,notice_link,notice_type,department,updatedBy,updatedAt) VALUES ` + - `(?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, + `INSERT INTO notices (id,title,timestamp,openDate,closeDate,important,attachments,email,isVisible,notice_link,notice_type,department,updatedBy,updatedAt,intranet) VALUES ` + + `(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, [ params.id, params.title, @@ -40,6 +40,7 @@ const handler = async (req, res) => { params.department, params.email, params.timestamp, + params.intranet, ] ).catch((err) => console.log(err)) return res.json(result) diff --git a/pages/api/update/[type].js b/pages/api/update/[type].js index 23b5a2a..c0060d8 100644 --- a/pages/api/update/[type].js +++ b/pages/api/update/[type].js @@ -23,8 +23,8 @@ const handler = async (req, res) => { params.main_attachment ) let result = await query( - `UPDATE notices SET title=?,updatedAt=?,openDate=?,closeDate=?,important=?,` + - `attachments=?,notice_link=?,isVisible=?,updatedBy=?,notice_type=? WHERE id=?`, + `UPDATE notices SET title=?,updatedAt=?,openDate=?,closeDate=?,important=?, + attachments=?,notice_link=?,isVisible=?,updatedBy=?,notice_type=?,intranet=? WHERE id=?`, [ params.title, params.timestamp, @@ -36,6 +36,7 @@ const handler = async (req, res) => { params.isVisible, params.email, params.notice_type, + params.intranet, params.id, ] ) diff --git a/scripts/create.js b/scripts/create.js index 8c94f1d..13a5667 100644 --- a/scripts/create.js +++ b/scripts/create.js @@ -40,6 +40,7 @@ async function migrate() { attachments varchar(1000), email varchar(50) NOT NULL, isDept int, + intranet int; department varchar(1000), PRIMARY KEY (id) );`).catch((e) => console.log(e))