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

Edit Page Enhancements #1319

Merged
merged 6 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/ui/NewsArticles/NewsArticles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
30 changes: 30 additions & 0 deletions app/pages/EditBreakingNewsPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
}
}

.breaking-news-form-buttons {
display: flex;
justify-content: center;
margin: 10px 0px;
}

.button-with-margin {
margin-right: 10px;
}
GeorgeCloud marked this conversation as resolved.
Show resolved Hide resolved

.breaking-news-footer {
display: flex;
justify-content: center;
Expand All @@ -47,3 +57,23 @@
.labelSubtext {
color: $color-grey5;
}

.round-edges {
width: 80px;
height: 30px;
border-radius: 10%;
display: flex;
align-items: center;
justify-content: center;
GeorgeCloud marked this conversation as resolved.
Show resolved Hide resolved
font-weight: bold;
}

.active-status {
color: white;
background-color: $color-status-amber;
GeorgeCloud marked this conversation as resolved.
Show resolved Hide resolved
}

.inactive-status {
color: white;
background-color: red;
}
GeorgeCloud marked this conversation as resolved.
Show resolved Hide resolved
52 changes: 37 additions & 15 deletions app/pages/EditBreakingNewsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +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 (articleId) {
dataService.put(route, article);
if (articleId){
dataService.put(route, articleFromState);
alert(`Article "${articleFromState.headline}" has been updated!`)
GeorgeCloud marked this conversation as resolved.
Show resolved Hide resolved
} else {
dataService.post(route, article);
dataService.post(route, articleFromState);
alert(`Article "${articleFromState.headline}" has been created!`);
}
};

Expand Down Expand Up @@ -92,15 +101,14 @@ export const EditBreakingNewsPage = () => {
<form className="form" key={article.id}>
<div className="form-header">
<h2>{`Breaking News Article #${index + 1}`}</h2>
<button type="button" onClick={() => onSave(article.id)}>
<RiSave3Line />
Save
</button>
<button type="button" onClick={() => onDelete(article.id, index)}>
<RiDeleteBin5Line />
Delete
</button>
</div>
{
isActive(article) ? (
<div className={'round-edges active-status'}>Active</div>
) : (
<div className={'round-edges inactive-status'}>Inactive</div>
)
}
<label>
Headline
<input
Expand Down Expand Up @@ -165,6 +173,20 @@ export const EditBreakingNewsPage = () => {
onChange={(e) => onFieldChange(article.id, e)}
/>
</label>
<div className="breaking-news-form-buttons">
<button
type="button"
className="button-with-margin"
onClick={() => onSave(index)}
>
<RiSave3Line />
Save
</button>
<button type="button" onClick={() => onDelete(article.id, index)}>
<RiDeleteBin5Line />
Delete
</button>
</div>
</form>
);

Expand Down
Loading