Skip to content

Commit

Permalink
Set withdrawn date input box to deactivated if work status isn't out …
Browse files Browse the repository at this point in the history
…of print or withdrawn; fixed bug to reset withdrawn date to None based on work status
  • Loading branch information
brendan-oconnell committed Apr 18, 2024
1 parent e18407f commit 8c98b68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions thoth-app/src/component/new_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Component for NewWorkComponent {
} else if let Ok(result) = self.doi.parse::<Doi>() {
self.work.doi.neq_assign(Some(result));
}
// Clear any fields which are not applicable to the currently selected work type.
// Clear any fields which are not applicable to the currently selected work type or work status.
// (Do not clear them before the save point as the user may change the type again.)
if self.work.work_type == WorkType::BookChapter {
self.work.edition = None;
Expand All @@ -289,7 +289,7 @@ impl Component for NewWorkComponent {
self.work.last_page = None;
self.work.page_interval = None;
}
if self.work.work_status == WorkStatus::OutOfPrint {
if self.work.work_status != WorkStatus::WithdrawnFromSale && self.work.work_status != WorkStatus::OutOfPrint {
self.work.withdrawn_date = None;
}
let body = CreateWorkRequestBody {
Expand Down
26 changes: 10 additions & 16 deletions thoth-app/src/component/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ impl Component for WorkComponent {
self.work.last_page = None;
self.work.page_interval = None;
}
if self.work.work_status != WorkStatus::WithdrawnFromSale && self.work.work_status != WorkStatus::OutOfPrint {
self.work.withdrawn_date = None;
}
let body = UpdateWorkRequestBody {
variables: UpdateVariables {
work_id: self.work.work_id,
Expand Down Expand Up @@ -565,6 +568,7 @@ impl Component for WorkComponent {
// Grey out chapter-specific or "book"-specific fields
// based on currently selected work type.
let is_chapter = self.work.work_type == WorkType::BookChapter;
let is_not_withdrawn_or_out_of_print = self.work.work_status != WorkStatus::WithdrawnFromSale && self.work.work_status != WorkStatus::OutOfPrint;
html! {
<>
<nav class="level">
Expand Down Expand Up @@ -640,22 +644,12 @@ impl Component for WorkComponent {
value={ self.work.publication_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeDate(e.to_value())) }
/>
{
if self.work.work_status == WorkStatus::WithdrawnFromSale || self.work.work_status == WorkStatus::OutOfPrint {
html! {
<>
<FormDateInput
label = "Withdrawn Date"
value={ self.work.withdrawn_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeWithdrawnDate(e.to_value())) }
/>
</>
}
} else {
html!{}
}
}

<FormDateInput
label = "Withdrawn Date"
value={ self.work.withdrawn_date.clone() }
oninput={ ctx.link().callback(|e: InputEvent| Msg::ChangeWithdrawnDate(e.to_value())) }
deactivated={ is_not_withdrawn_or_out_of_print }
/>
<FormTextInput
label = "Place of Publication"
value={ self.work.place.clone() }
Expand Down

0 comments on commit 8c98b68

Please sign in to comment.