Skip to content

Commit

Permalink
Added Inactive school message
Browse files Browse the repository at this point in the history
  • Loading branch information
deepikagonuguntla committed Jan 3, 2025
1 parent edcb292 commit 272c5ed
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/faqs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def show
store_user_location!
end
# Get all frequently asked questions by position ASC order.
render json: { faqs: Faq.get_faqs }
render json: { faqs: Faq.get_faqs, is_school_active: current_user&.school&.active || false }
end
end
2 changes: 1 addition & 1 deletion app/controllers/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def index
schools_arr << school_hash
end
school_not_found = schools_arr.length <= 0 ? "There are no results that match your search criteria." : ""
render json: { schools: schools_arr, anchor_tags: anchor_tags, school_not_found: school_not_found }
render json: { schools: schools_arr, anchor_tags: anchor_tags, school_not_found: school_not_found, is_school_active: current_user&.school&.active || false }
end

def participating_schools_data; end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/teacher_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ def index
total_count = total_count['value'] if total_count.is_a?(Hash)
total_pages = (total_count / per_page.to_f).ceil

no_results_found_msg = @teacher_sets.length <= 0 ? "No results found." : ""
no_results_found_msg = @teacher_sets.length <= 0 ? "No results found." : ""

render json: { teacher_sets: @teacher_sets, facets: facets, total_count: total_count, total_pages: total_pages,
no_results_found_msg: no_results_found_msg, tsSubjectsHash: subjects_hash, resetPageNumber: reset_page_number, errrorMessage: "" }
no_results_found_msg: no_results_found_msg, tsSubjectsHash: subjects_hash, resetPageNumber: reset_page_number, errrorMessage: "",
is_school_active: current_user&.school&.active || false }
rescue ElasticsearchException => e
render json: { errrorMessage: "We are having trouble retrieving Teacher Set data right now. Please try again later", teacher_sets: {}, facets: {} }
rescue StandardError => e
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def create
User.create(user_params)
end

def user_school
render :json => { school: current_user.present? ? current_user.school : {} }
end

private

# Strong parameters: protect object creation and allow mass assignment.
Expand Down
13 changes: 12 additions & 1 deletion app/javascript/components/AppBreadcrumbs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
Heading,
Hero,
useColorModeValue,
Banner
} from "@nypl/design-system-react-components";

export default function AppBreadcrumbs() {
export default function AppBreadcrumbs(props) {
const heroBgColor = useColorModeValue(
"var(--nypl-colors-brand-primary)",
"var(--nypl-colors-dark-ui-bg-hover)"
Expand Down Expand Up @@ -82,6 +83,15 @@ export default function AppBreadcrumbs() {
}
};

const inactiveSchoolMessage = () => {
console.log(props.is_school_active)
if (props.is_school_active === false) {
return (<Banner className="inactiveSchool" content={<>
Your school is inactive, so your account is restricted. Please contact help@mylibrarynyc.org.
</>} type="warning"/>)
}
}

const HeroDataValue = (levelString) => {
switch (levelString) {
case "participating-schools":
Expand Down Expand Up @@ -136,6 +146,7 @@ export default function AppBreadcrumbs() {
/>
}
/>
{inactiveSchoolMessage()}
</>
);
}
16 changes: 14 additions & 2 deletions app/javascript/components/Contact/Contact.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import AppBreadcrumbs from "./../AppBreadcrumbs";
import HaveQuestions from "./../HaveQuestions/HaveQuestions";
import {
Expand All @@ -10,18 +10,30 @@ import {
useColorMode,
} from "@nypl/design-system-react-components";

import axios from "axios";

function Contact() {
const { colorMode } = useColorMode();
const [isSchoolActive, setIsSchoolActive] = useState("");

useEffect(() => {
document.title = "Contact | MyLibraryNYC";
if (env.RAILS_ENV !== "test") {
window.scrollTo(0, 0);
}
axios
.get("/user_school")
.then((res) => {
setIsSchoolActive(res.data.school.active)
})
.catch(function (error) {
console.log(error);
});
}, []);

return (
<TemplateAppContainer
breakout={<AppBreadcrumbs />}
breakout={<AppBreadcrumbs is_school_active={isSchoolActive}/>}
contentPrimary={
<div id="contacts-page">
<Heading
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/components/Faqs/Faqs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function Faqs(props) {

const [faqs, setFaqs] = useState([]);
const { colorMode } = useColorMode();
const [isSchoolActive, setIsSchoolActive] = useState("");

useEffect(() => {
document.title = "Frequently Asked Questions | MyLibraryNYC";
Expand All @@ -25,6 +26,7 @@ export default function Faqs(props) {
.get("/faqs/show")
.then((res) => {
setFaqs(res.data.faqs);
setIsSchoolActive(res.data.is_school_active)
})
.catch(function (error) {
console.log(error);
Expand Down Expand Up @@ -52,7 +54,7 @@ export default function Faqs(props) {

return (
<TemplateAppContainer
breakout={<AppBreadcrumbs />}
breakout={<AppBreadcrumbs is_school_active={isSchoolActive} />}
contentTop={<SignedInMsg signInDetails={props} />}
contentPrimary={
<>
Expand Down
1 change: 0 additions & 1 deletion app/javascript/components/Home/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from "react";
import HaveQuestions from "./../HaveQuestions/HaveQuestions";
import AppBreadcrumbs from "./../AppBreadcrumbs";
import AccessDigitalResources from "../AccessDigitalResources/AccessDigitalResources";
import CalendarOfEvents from "./../CalendarOfEvents";
import NewsLetter from "../NewsLetter/NewsLetter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function ParticipatingSchools(props) {
const [anchor_tags, setAnchorTags] = useState([]);
const [schoolNotFound, setSchoolNotFound] = useState("");
const { colorMode } = useColorMode();
const [isSchoolActive, setIsSchoolActive] = useState("");

useEffect(() => {
document.title = "Participating Schools | MyLibraryNYC";
Expand All @@ -35,6 +36,7 @@ export default function ParticipatingSchools(props) {
setSchools(res.data.schools);
setAnchorTags(res.data.anchor_tags);
setSchoolNotFound(res.data.school_not_found);
setIsSchoolActive(res.data.is_school_active)
})
.catch(function (error) {
console.log(error);
Expand Down Expand Up @@ -197,7 +199,7 @@ export default function ParticipatingSchools(props) {

return (
<TemplateAppContainer
breakout={<AppBreadcrumbs />}
breakout={<AppBreadcrumbs is_school_active={isSchoolActive} />}
contentTop={<SignedInMsg signInDetails={props} />}
contentPrimary={
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default function SearchTeacherSets(props) {
const [showKeyword, setShowKeyWord] = useState(false);
const [updateKeyword, setUpdateKeyword] = useState("");
const location = useLocation();
const [isSchoolActive, setIsSchoolActive] = useState("");
const [selectedSortOption, setSelectedSortOption] = useState("Newest to oldest");

useEffect(() => {
Expand Down Expand Up @@ -252,6 +253,7 @@ export default function SearchTeacherSets(props) {
setTsSubjects(res.data.tsSubjectsHash);
setResetPageNumber(res.data.resetPageNumber);
setTeacherSetDataNotRetrievedMsg(res.data.errrorMessage);
setIsSchoolActive(res.data.is_school_active)
if (res.data.teacher_sets.length > 0 && res.data.total_count > 10) {
setDisplayPagination("block");
} else {
Expand Down Expand Up @@ -1261,7 +1263,7 @@ export default function SearchTeacherSets(props) {

return (
<TemplateAppContainer
breakout={<AppBreadcrumbs />}
breakout={<AppBreadcrumbs is_school_active={isSchoolActive} />}
contentTop={
<>
{<SignedInMsg signInDetails={props} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export default function TeacherSetDetails(props) {

const inactiveSchoolMessage = () => {
if (currentUserStatus && isSchoolActive === false) {
return (<Banner content={<>
return (<Banner className="inactiveSchool" content={<>
Your school is inactive, so your account is restricted. Please contact help@mylibrarynyc.org.
</>} type="warning" />)
}
Expand Down Expand Up @@ -802,12 +802,12 @@ export default function TeacherSetDetails(props) {
/>
}
/>
{inactiveSchoolMessage()}
</>
}
contentTop={
<>
{errorMsg()}
{inactiveSchoolMessage()}
</>
}
contentPrimary={
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,7 @@ ul.list li:before {
flex-shrink: none !important;
}
}

.inactiveSchool {
padding-left: var(--nypl-sizes-36);
}
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

match '/home/get_mln_file_names' => 'home#mln_file_names', via: [:get]
match '/secondary_menu' => 'home#secondary_menu', via: [:get]
match '/user_school' => 'users#user_school', via: [:get]

match '/news_letter/validate_news_letter_email_from_user_sign_up_page' => 'news_letter#validate_news_letter_email_from_user_sign_up_page',
via: [:get, :post]
Expand Down

0 comments on commit 272c5ed

Please sign in to comment.