From 116db4068a9847f41815aa672bcb7657f7dcd6b6 Mon Sep 17 00:00:00 2001 From: Reveal Date: Tue, 6 Feb 2024 11:54:57 -0800 Subject: [PATCH 1/6] move article save/delete buttons to bottom of the edit/create form --- app/pages/EditBreakingNewsPage.scss | 10 +++++++++ app/pages/EditBreakingNewsPage.tsx | 34 +++++++++++++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/pages/EditBreakingNewsPage.scss b/app/pages/EditBreakingNewsPage.scss index d37d509ea..caa3f6cf0 100644 --- a/app/pages/EditBreakingNewsPage.scss +++ b/app/pages/EditBreakingNewsPage.scss @@ -38,6 +38,16 @@ } } +.breaking-news-form-buttons { + display: flex; + justify-content: center; + margin: 10px 0px; +} + +.button-with-margin { + margin-right: 10px; +} + .breaking-news-footer { display: flex; justify-content: center; diff --git a/app/pages/EditBreakingNewsPage.tsx b/app/pages/EditBreakingNewsPage.tsx index a0db343f0..242870689 100644 --- a/app/pages/EditBreakingNewsPage.tsx +++ b/app/pages/EditBreakingNewsPage.tsx @@ -52,10 +52,14 @@ export const EditBreakingNewsPage = () => { ); const route = `/api/news_articles/${articleId ?? ""}`; - if (articleId) { - dataService.put(route, article); - } else { - dataService.post(route, article); + if (article) { + if (articleId){ + dataService.put(route, article); + alert(`Article "${article.headline}" has been updated!`) + } else { + dataService.post(route, article); + alert(`Article "${article.headline}" has been created!`) + } } }; @@ -92,14 +96,6 @@ export const EditBreakingNewsPage = () => {

{`Breaking News Article #${index + 1}`}

- -
+
+ + +
); From ceaa76bbaf2c1f817e629e6580d0fff63ca60d8e Mon Sep 17 00:00:00 2001 From: GeorgeCloud Date: Thu, 8 Feb 2024 00:29:32 -0800 Subject: [PATCH 2/6] add active/inactive status bars to breaking news articles --- .../ui/NewsArticles/NewsArticles.tsx | 2 +- app/pages/EditBreakingNewsPage.scss | 20 ++++++++++ app/pages/EditBreakingNewsPage.tsx | 38 ++++++++++++------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/components/ui/NewsArticles/NewsArticles.tsx b/app/components/ui/NewsArticles/NewsArticles.tsx index e46902cd1..09c7955f8 100644 --- a/app/components/ui/NewsArticles/NewsArticles.tsx +++ b/app/components/ui/NewsArticles/NewsArticles.tsx @@ -64,7 +64,7 @@ export const NewsArticles = () => { useEffect(() => { const fetchBreakingNewsArticles = async () => { - const response = await dataService.get("/api/news_articles"); + const response = await dataService.get("/api/news_articles?active=true"); const { news_articles }: { news_articles: NewsArticle[] } = response; setBreakingNewsArticles(news_articles); }; diff --git a/app/pages/EditBreakingNewsPage.scss b/app/pages/EditBreakingNewsPage.scss index caa3f6cf0..533bf517a 100644 --- a/app/pages/EditBreakingNewsPage.scss +++ b/app/pages/EditBreakingNewsPage.scss @@ -57,3 +57,23 @@ .labelSubtext { color: $color-grey5; } + +.round-edges { + width: 80px; + height: 30px; + border-radius: 10%; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; +} + +.active-status { + color: white; + background-color: $color-status-amber; +} + +.inactive-status { + color: white; + background-color: red; +} diff --git a/app/pages/EditBreakingNewsPage.tsx b/app/pages/EditBreakingNewsPage.tsx index 242870689..7d6e76afa 100644 --- a/app/pages/EditBreakingNewsPage.tsx +++ b/app/pages/EditBreakingNewsPage.tsx @@ -46,20 +46,25 @@ export const EditBreakingNewsPage = () => { ]); }; - const onSave = (articleId: string) => { - const article = breakingNewsArticles.find( - ({ id }: any) => id === articleId - ); + const isActive = (article: NewsArticle): boolean => { + const today = new Date(); + const isEffective = !article.effective_date || new Date(article.effective_date) <= today; + const isNotExpired = !article.expiration_date || new Date(article.expiration_date) >= today; + + return Boolean(article.id && isEffective && isNotExpired); + }; + + const onSave = (index: number) => { + const articleFromState = breakingNewsArticles[index]; + const articleId = articleFromState.id const route = `/api/news_articles/${articleId ?? ""}`; - if (article) { - if (articleId){ - dataService.put(route, article); - alert(`Article "${article.headline}" has been updated!`) - } else { - dataService.post(route, article); - alert(`Article "${article.headline}" has been created!`) - } + if (articleId){ + dataService.put(route, articleFromState); + alert(`Article "${articleFromState.headline}" has been updated!`) + } else { + dataService.post(route, articleFromState); + alert(`Article "${articleFromState.headline}" has been created!`); } }; @@ -97,6 +102,13 @@ export const EditBreakingNewsPage = () => {

{`Breaking News Article #${index + 1}`}

+ { + isActive(article) ? ( +
Active
+ ) : ( +
Inactive
+ ) + }