Skip to content

Commit

Permalink
Merge pull request #1482 from NYPL/MLN-1304
Browse files Browse the repository at this point in the history
Added school active condition in all the pages
  • Loading branch information
gonuguntla authored Jan 3, 2025
2 parents 15f26a8 + 7c631f8 commit 426e7a3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 22 deletions.
7 changes: 4 additions & 3 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def show
@book = Book.find params[:id]
# If the bib record has "n" or "e" in the "Bib Code 3 field" we should not show the "View in catalog" link on the book show page.
render json: {
:book => @book.as_json,
:teacher_sets => @book.teacher_sets.as_json,
:show_catalog_link => !%w[n e].include?(@book.bib_code_3)
book: @book.as_json,
teacher_sets: @book.teacher_sets.as_json,
show_catalog_link: !%w[n e].include?(@book.bib_code_3),
is_school_active: current_user.present? ? current_user.is_school_active? : nil
}
end

Expand Down
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, is_school_active: current_user&.school&.active || false }
render json: { faqs: Faq.get_faqs, is_school_active: current_user.present? ? current_user.is_school_active? : nil }
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, is_school_active: current_user&.school&.active || false }
render json: { schools: schools_arr, anchor_tags: anchor_tags, school_not_found: school_not_found, is_school_active: current_user.present? ? current_user.is_school_active? : nil }
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 @@ -67,7 +67,8 @@ def index

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: "",
is_school_active: current_user&.school&.active || false }
is_school_active: current_user.present? ? current_user.is_school_active? : nil }

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 Expand Up @@ -177,7 +178,7 @@ def show
allowed_quantities: allowed_quantities,
books: ts_books,
teacher_set_notes: @set.teacher_set_notes,
is_school_active: current_user&.school&.active || false
is_school_active: current_user.present? ? current_user.is_school_active? : nil
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create
end

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

private
Expand Down
41 changes: 27 additions & 14 deletions app/javascript/components/TeacherSetBooks/TeacherSetBooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
useColorMode,
Hero,
useColorModeValue,
Banner,
} from "@nypl/design-system-react-components";

import ShowBookImage from "./../ShowBookImage";
Expand All @@ -35,6 +36,7 @@ export default function TeacherSetBooks() {
const [tsTitle, setTsTitle] = useState('');
const [teacherSets, setTeacherSets] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [isSchoolActive, setIsSchoolActive] = useState("");
const { colorMode } = useColorMode();
const heroBgColor = useColorModeValue(
"var(--nypl-colors-brand-primary)",
Expand Down Expand Up @@ -93,6 +95,7 @@ export default function TeacherSetBooks() {
.get("/books/" + params["id"])
.then((res) => {
setTeacherSets(res.data.teacher_sets);
setIsSchoolActive(res.data.is_school_active);
setBook(res.data.book);
if (env.RAILS_ENV !== "test" && env.RAILS_ENV !== "development") {
adobeAnalyticsForTeacherSetBooks(res.data.book)
Expand Down Expand Up @@ -228,6 +231,15 @@ export default function TeacherSetBooks() {
);
};

const inactiveSchoolMessage = () => {
console.log(isSchoolActive === false)
if (isSchoolActive === false) {
return (<Banner className="inactiveSchool" content={<>
Your school is inactive, so your account is restricted. Please contact [email protected].
</>} type="warning"/>)
}
}

const BookImage = (data) => {
if (isLoading) {
return (
Expand Down Expand Up @@ -287,20 +299,21 @@ export default function TeacherSetBooks() {
breadcrumbsType="booksAndMore"
/>
<Hero
heroType="tertiary"
foregroundColor={heroFgColor}
backgroundColor={heroBgColor}
heading={
<Heading
level="h1"
color="ui.white"
id={
"hero-" + window.location.pathname.split(/\/|\?|&|=|\./g)[1]
}
text="Book Details"
/>
}
/>
heroType="tertiary"
foregroundColor={heroFgColor}
backgroundColor={heroBgColor}
heading={
<Heading
level="h1"
color="ui.white"
id={
"hero-" + window.location.pathname.split(/\/|\?|&|=|\./g)[1]
}
text="Book Details"
/>
}
/>
{inactiveSchoolMessage()}
</>
}
contentPrimary={
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def send_unsubscribe_notification_email
UserMailer.unsubscribe(self).deliver
end

def is_school_active?
school.present? && school.active
end

# If the user's barcode is not yet finalized, then set its status to
# 'pending' and save. In the future, there may be other conditions that
# could set the user to "pending", and we'll be checking for those here, as well.
Expand Down

0 comments on commit 426e7a3

Please sign in to comment.