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

[NEW] Announcement component #114

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
31 changes: 31 additions & 0 deletions app/components/announcement.js
Original file line number Diff line number Diff line change
@@ -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 (
<a
href={props.announcement.redirect_url}
className={`d-flex flex-column align-items-center p-2 ${styles.announcement} ${styles.announcement_link}`}
>
<h6 className={`pt-1`} >{props.announcement.announcement_text}</h6>
</a>
);
}
20 changes: 11 additions & 9 deletions app/components/layout.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Announcement announcement={props.menu.announcement} />
<Menubar menu={props.menu.topNavItems} />
{props.children}
<Footer></Footer>
{pathname === '/virtualconf/mainstage' && (
{pathname === "/virtualconf/mainstage" && (
<p className={styles.announcement}>
<span className={styles.announcement__svg}>
<BookmarkSVG />
</span>{' '}
Bookmark this page and come back on{' '}
</span>{" "}
Bookmark this page and come back on{" "}
<span className={styles.announcement__text}>April 6</span> for the
LIVE conference
</p>
Expand Down
17 changes: 17 additions & 0 deletions app/lib/announcement.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
4 changes: 3 additions & 1 deletion app/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions app/styles/Announcement.module.css
Original file line number Diff line number Diff line change
@@ -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);;
}





52 changes: 52 additions & 0 deletions cms/api/announcement/config/routes.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}
]
}
8 changes: 8 additions & 0 deletions cms/api/announcement/controllers/announcement.js
Original file line number Diff line number Diff line change
@@ -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 = {};
8 changes: 8 additions & 0 deletions cms/api/announcement/models/announcement.js
Original file line number Diff line number Diff line change
@@ -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 = {};
31 changes: 31 additions & 0 deletions cms/api/announcement/models/announcement.settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
8 changes: 8 additions & 0 deletions cms/api/announcement/services/announcement.js
Original file line number Diff line number Diff line change
@@ -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 = {};
21 changes: 21 additions & 0 deletions cms/config/functions/announcement.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
6 changes: 5 additions & 1 deletion cms/config/functions/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
};
13 changes: 11 additions & 2 deletions cms/config/functions/fetchData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { carousels,
subMenus,
topNavItem,
speakers,
forms } = require('../initialData');
forms,
announcements } = require('../initialData');
const { githubKit } = require('./github');

module.exports = async () => {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions cms/config/initialData/announcements.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
5 changes: 4 additions & 1 deletion cms/config/initialData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,5 +19,6 @@ module.exports = {
subMenus,
topNavItem,
forms,
speakers
speakers,
announcements
};
2 changes: 2 additions & 0 deletions docs/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ We at Rocket.Chat believe in building susatinable online communities which can

4. <a href="./inappchat">InAppChat Component</a>

5. <a href="./announcement">Announcement Component</a>

---


Expand Down
Loading