diff --git a/app/components/announcement.js b/app/components/announcement.js
new file mode 100644
index 00000000..be30ba15
--- /dev/null
+++ b/app/components/announcement.js
@@ -0,0 +1,31 @@
+import styles from "../styles/Announcement.module.css";
+
+export default function Announcement(props) {
+
+ if (
+ typeof props.announcement === "undefined" ||
+ typeof props.announcement.announcement_text === "undefined"
+ ) {
+ return <>>;
+ }
+
+ const announcementPublishDateTime = new Date(props.announcement.publish_date);
+ const announcementUnpublishDateTime = new Date(props.announcement.unpublish_date);
+ const currentDateTime = new Date();
+
+ if (
+ currentDateTime < announcementPublishDateTime ||
+ currentDateTime > announcementUnpublishDateTime
+ ) {
+ return <>>;
+ }
+
+ return (
+
+ {props.announcement.announcement_text}
+
+ );
+}
diff --git a/app/components/layout.js b/app/components/layout.js
index 03bb2d5d..039a930f 100644
--- a/app/components/layout.js
+++ b/app/components/layout.js
@@ -1,23 +1,25 @@
-import '../styles/Layout.module.css';
-import Footer from './footer';
-import Menubar from './menubar';
-import BookmarkSVG from '/public/svg/bookmark.js';
-import styles from '../styles/Mainstage.module.css';
-import { useRouter } from 'next/router';
+import "../styles/Layout.module.css";
+import Footer from "./footer";
+import Menubar from "./menubar";
+import Announcement from "./announcement";
+import BookmarkSVG from "/public/svg/bookmark.js";
+import styles from "../styles/Mainstage.module.css";
+import { useRouter } from "next/router";
function Layout(props) {
const { pathname } = useRouter();
return (
<>
+
{props.children}
- {pathname === '/virtualconf/mainstage' && (
+ {pathname === "/virtualconf/mainstage" && (
- {' '}
- Bookmark this page and come back on{' '}
+ {" "}
+ Bookmark this page and come back on{" "}
April 6 for the
LIVE conference
diff --git a/app/lib/announcement.js b/app/lib/announcement.js
new file mode 100644
index 00000000..85340913
--- /dev/null
+++ b/app/lib/announcement.js
@@ -0,0 +1,17 @@
+import { fetchAPI } from "./api";
+
+
+export const getAnnouncementData = async (announcement_code) => {
+ try {
+ const res = await fetchAPI("/announcements");
+ let neededAnnouncement = new Object();
+ res.forEach((announcement) => {
+ if (announcement.announcement_code === announcement_code) {
+ neededAnnouncement = announcement;
+ }
+ });
+ return neededAnnouncement;
+ } catch (error) {
+ console.log(error);
+ }
+};
diff --git a/app/pages/index.js b/app/pages/index.js
index 95cc2a98..6a33546f 100644
--- a/app/pages/index.js
+++ b/app/pages/index.js
@@ -10,6 +10,7 @@ import { Container, Col } from 'react-bootstrap';
import { fetchAPI } from '../lib/api';
import { withFirebaseAuthUser } from '../components/auth/firebase';
import { INFOTILES_DATA } from '../lib/const/infotiles';
+import { getAnnouncementData } from '../lib/announcement';
function Home(props) {
return (
@@ -83,9 +84,10 @@ export async function getStaticProps({ params }) {
const releaseNotes = await fetchAPI('/release-notes');
const topNavItems = await fetchAPI('/top-nav-item');
const topPosts = await fetchAPI('/discourses');
+ const announcement = await getAnnouncementData('rc_alumini_conf');
return {
- props: { carousels, personas, guides, releaseNotes, topNavItems, topPosts },
+ props: { carousels, personas, guides, releaseNotes, topNavItems, topPosts, announcement},
// Next.js will attempt to re-generate the page:
// - When a request comes in
// - At most once every 1 second
diff --git a/app/styles/Announcement.module.css b/app/styles/Announcement.module.css
new file mode 100644
index 00000000..138b5720
--- /dev/null
+++ b/app/styles/Announcement.module.css
@@ -0,0 +1,31 @@
+
+.announcement {
+ background: rgb(255,255,255);
+ background: linear-gradient(45deg, rgb(255, 132, 132) 0%, rgba(255,0,0,1) 100%);
+}
+
+.announcement:hover{
+ background: rgb(255,61,61);
+ background: linear-gradient(45deg, rgb(252, 24, 24) 0%, rgb(226, 18, 18) 100%);
+}
+
+.announcement_link{
+ width: inherit;
+ height: inherit;
+ text-decoration: none;
+ color: white;
+}
+
+.announcement_link:hover{
+ text-decoration: none;
+ color: white;
+}
+
+.announcement_text {
+ font-size: clamp(16px, 2.4vw, 20px);;
+}
+
+
+
+
+
\ No newline at end of file
diff --git a/cms/api/announcement/config/routes.json b/cms/api/announcement/config/routes.json
new file mode 100644
index 00000000..35a60e24
--- /dev/null
+++ b/cms/api/announcement/config/routes.json
@@ -0,0 +1,52 @@
+{
+ "routes": [
+ {
+ "method": "GET",
+ "path": "/announcements",
+ "handler": "announcement.find",
+ "config": {
+ "policies": []
+ }
+ },
+ {
+ "method": "GET",
+ "path": "/announcements/count",
+ "handler": "announcement.count",
+ "config": {
+ "policies": []
+ }
+ },
+ {
+ "method": "GET",
+ "path": "/announcements/:id",
+ "handler": "announcement.findOne",
+ "config": {
+ "policies": []
+ }
+ },
+ {
+ "method": "POST",
+ "path": "/announcements",
+ "handler": "announcement.create",
+ "config": {
+ "policies": []
+ }
+ },
+ {
+ "method": "PUT",
+ "path": "/announcements/:id",
+ "handler": "announcement.update",
+ "config": {
+ "policies": []
+ }
+ },
+ {
+ "method": "DELETE",
+ "path": "/announcements/:id",
+ "handler": "announcement.delete",
+ "config": {
+ "policies": []
+ }
+ }
+ ]
+}
diff --git a/cms/api/announcement/controllers/announcement.js b/cms/api/announcement/controllers/announcement.js
new file mode 100644
index 00000000..e8608953
--- /dev/null
+++ b/cms/api/announcement/controllers/announcement.js
@@ -0,0 +1,8 @@
+'use strict';
+
+/**
+ * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
+ * to customize this controller
+ */
+
+module.exports = {};
diff --git a/cms/api/announcement/models/announcement.js b/cms/api/announcement/models/announcement.js
new file mode 100644
index 00000000..0054d33c
--- /dev/null
+++ b/cms/api/announcement/models/announcement.js
@@ -0,0 +1,8 @@
+'use strict';
+
+/**
+ * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks)
+ * to customize this model
+ */
+
+module.exports = {};
diff --git a/cms/api/announcement/models/announcement.settings.json b/cms/api/announcement/models/announcement.settings.json
new file mode 100644
index 00000000..abbec13a
--- /dev/null
+++ b/cms/api/announcement/models/announcement.settings.json
@@ -0,0 +1,31 @@
+{
+ "kind": "collectionType",
+ "collectionName": "announcements",
+ "info": {
+ "name": "Announcement",
+ "description": ""
+ },
+ "options": {
+ "increments": true,
+ "timestamps": true,
+ "draftAndPublish": true
+ },
+ "pluginOptions": {},
+ "attributes": {
+ "announcement_text": {
+ "type": "string"
+ },
+ "publish_date": {
+ "type": "datetime"
+ },
+ "redirect_url": {
+ "type": "string"
+ },
+ "unpublish_date": {
+ "type": "datetime"
+ },
+ "announcement_code": {
+ "type": "string"
+ }
+ }
+}
diff --git a/cms/api/announcement/services/announcement.js b/cms/api/announcement/services/announcement.js
new file mode 100644
index 00000000..6538a8c8
--- /dev/null
+++ b/cms/api/announcement/services/announcement.js
@@ -0,0 +1,8 @@
+'use strict';
+
+/**
+ * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services)
+ * to customize this service
+ */
+
+module.exports = {};
diff --git a/cms/config/functions/announcement.js b/cms/config/functions/announcement.js
new file mode 100644
index 00000000..4b413acb
--- /dev/null
+++ b/cms/config/functions/announcement.js
@@ -0,0 +1,21 @@
+module.exports.deleteOldAnnouncemts = async function () {
+ try {
+ let announcements = await strapi.query("announcement").find({});
+ announcements.forEach(async (announcement) => {
+ const announcementUnpublishDateTime = new Date(
+ announcement.unpublish_date
+ );
+ const currentDateTime = new Date();
+ if (
+ (currentDateTime - announcementUnpublishDateTime) / (1000 * 60 * 60) >
+ 2
+ ) {
+ await strapi.query("announcement").delete({
+ id: announcement.id,
+ });
+ }
+ });
+ } catch (error) {
+ console.log(error);
+ }
+};
diff --git a/cms/config/functions/cron.js b/cms/config/functions/cron.js
index 7cc9c418..6d22bc72 100644
--- a/cms/config/functions/cron.js
+++ b/cms/config/functions/cron.js
@@ -3,6 +3,7 @@ const { getLatestCommunityActivity } = require("./fetchTopPosts");
const { getCommunityContributors } = require("./fetchContributors")
const { githubKit } = require("./github");
const { updateSpeakerData } = require('./speaker')
+const { deleteOldAnnouncemts } = require("./announcement")
/**
* Cron config that gives you an opportunity
* to run scheduled jobs.
@@ -28,7 +29,10 @@ module.exports = {
getCommunityContributors('https://gsoc.rocket.chat/api/data','rocketChat','Rocket.Chat');
updateSpeakerData();
},
- '*/* 10 * * * *': () => {
+ '* */10 * * * *': () => {
githubKit('RocketChat','RC4Community',['issues','contributors','pulls']);
+ },
+ '* * * */1 * *': () => {
+ deleteOldAnnouncemts();
}
};
\ No newline at end of file
diff --git a/cms/config/functions/fetchData.js b/cms/config/functions/fetchData.js
index 78a09064..ae5c04ec 100644
--- a/cms/config/functions/fetchData.js
+++ b/cms/config/functions/fetchData.js
@@ -6,7 +6,8 @@ const { carousels,
subMenus,
topNavItem,
speakers,
- forms } = require('../initialData');
+ forms,
+ announcements } = require('../initialData');
const { githubKit } = require('./github');
module.exports = async () => {
@@ -22,7 +23,8 @@ module.exports = async () => {
var formCount = await strapi.query("form").count();
var ghrepos = await strapi.query("github-repositories").count({});
var speakersCount = await strapi.query("speaker").count({});
-
+ var announcementsCount = await strapi.query("announcement").count({});
+
// initial fetch
speakers.map(async (speaker, index) => {
if (index <= speakersCount - 1) {
@@ -245,6 +247,13 @@ module.exports = async () => {
}),
});
}
+
+ if (announcementsCount === 0) {
+ announcements.forEach(async (announcement) => {
+ await strapi.query("announcement").create(announcement);
+ });
+ }
+
} catch (error) {
console.log("Error:= ", error);
}
diff --git a/cms/config/initialData/announcements.json b/cms/config/initialData/announcements.json
new file mode 100644
index 00000000..c15dd126
--- /dev/null
+++ b/cms/config/initialData/announcements.json
@@ -0,0 +1,9 @@
+[
+ {
+ "announcement_text": "Attend RocketChat's GSoC Alumni Virtual Conference on 6th April !",
+ "publish_date": "2022-03-28T06:30:00.000Z",
+ "redirect_url": "/virtualconf/mainstage",
+ "unpublish_date": "2022-04-07T06:30:00.000Z",
+ "announcement_code": "rc_alumini_conf"
+ }
+]
\ No newline at end of file
diff --git a/cms/config/initialData/index.js b/cms/config/initialData/index.js
index 5512a755..99f52daf 100644
--- a/cms/config/initialData/index.js
+++ b/cms/config/initialData/index.js
@@ -7,6 +7,8 @@ const subMenus = require("./sub-menus.json");
const topNavItem = require("./top-nav-item.json");
const forms = require("./forms.json")
const speakers = require("./speakers.json")
+const announcements = require("./announcements.json")
+
module.exports = {
carousels,
@@ -17,5 +19,6 @@ module.exports = {
subMenus,
topNavItem,
forms,
- speakers
+ speakers,
+ announcements
};
\ No newline at end of file
diff --git a/docs/components/README.md b/docs/components/README.md
index 8a780586..fe4eda68 100644
--- a/docs/components/README.md
+++ b/docs/components/README.md
@@ -13,6 +13,8 @@ We at Rocket.Chat believe in building susatinable online communities which can
4. InAppChat Component
+5. Announcement Component
+
---
diff --git a/docs/components/announcement/README.md b/docs/components/announcement/README.md
new file mode 100644
index 00000000..1809af90
--- /dev/null
+++ b/docs/components/announcement/README.md
@@ -0,0 +1,79 @@
+# Announcemnet Component
+
+The Announcemnt allows community builders to add an announcemnt at the top of any page.
+
+
+
+
+## Announcement Component Props
+
+We use our helper function `getAnnouncementData(announcement_code);` to fetch the data for the component inorder for it to be visible and pass it as `announcement` object in the props passed to the page.The announcement prop will be automtically then passed to the component in the layout.
+
+| Prop Name | Description | Type |
+| ------------- |------------------------- | -----|
+| announcement | This will contain the details of the announcement | JSON |
+
+# Usage
+
+### Setting up component data in CMS
+
+1. Add the Announcement details in the backend under the announcemnts collection.
+
+
+
+2. The publish_date is the date when we want the announcemnt to be displayed on the.
+3. Announcement Code should be unqiue as it will be used to fetch the announcemnt details on the page where we wish to display the announcement.
+4. The `deleteOldAnnouncemts()` runs once a day to delete the announcements which have crossed the unpublish_date, this helps us avoid cluttering of old announcemnts form the database.
+
+NOTE : If you want any initial announcement to be added to the database during initialization when we run , `INITIALIZE_DATA=true npm run develop` , add that announcemnt in json format in `cms/config/initialdata/annoucements.json`. This will populate the DB with the announcemnt at the time data is initialised.
+
+### Using the component
+
+```
+import Head from "next/head";
+import { Github } from '../components/github';
+import { githubKitData } from '../lib/github';
+import { getAnnouncementData } from '../lib/announcement';
+
+export default function Leaderboardpage(props){
+ return (
+
+
+
GSOC2022 LeaderBoard
+
+
+
+ Repository Overview
+
+
+
+
+ );
+}
+
+export async function getStaticProps(){
+
+ const githubData = await githubKitData('RocketChat','RC4Community',['issues','pulls','contributors']);
+ const topNavItems = await fetchAPI("/top-nav-item");
+
+ //the helper function will fetch the relevant anouncement data linked to announcemnt with code 'rc_alumini_conf'
+ //Now we will have to pass announcements to page props it and this will display the annoucement on the page
+ const announcement = await getAnnouncementData('rc_alumini_conf');
+
+ return {
+ props: {
+ leaderboardProps,
+ githubData,
+ announcement
+ },
+ revalidate: 30,
+ };
+}
+```
+
+
+
+
+
+
+### :arrow_left: Explore More Components
\ No newline at end of file