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

React autosave: patient dashboard form (bugs fixed 🙂 ) #3337

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions app/javascript/src/components/PatientDashboardForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default PatientDashboardForm = ({

const autosave = async (updatedData) => {
const updatedPatientData = { ...patientData, ...updatedData }
setPatientData(updatedPatientData)

const putData = {
name: updatedPatientData.name,
Expand All @@ -44,9 +43,9 @@ export default PatientDashboardForm = ({
}
}

const debouncedAutosave = useMemo((params) => {
return debounce(autosave, 300)
}, []);
const debouncedAutosave = (params) => {
return debounce(autosave(params), 300)
};

// Stop the invocation of the debounced function after unmounting
useEffect(() => {
Expand Down Expand Up @@ -131,6 +130,7 @@ export default PatientDashboardForm = ({
label={i18n.t('patient.shared.status')}
value={patientData.status}
className="form-control-plaintext"
disabled="true"
tooltip={statusTooltip}
onChange={e => debouncedAutosave({ status: e.target.value })}
/>
Expand Down
87 changes: 11 additions & 76 deletions app/views/patients/_patient_dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -1,77 +1,12 @@
<div id="patient_dashboard_content">
<%= bootstrap_form_with model: patient,
html: { id: 'patient_dashboard_form' },
local: false,
method: 'patch',
class: 'edit_patient' do |f| %>
<div class="row">

<div class="col-4">
<%= f.text_field :name,
label: t('patient.shared.name'),
autocomplete: 'off' %>
</div>

<div class="col">
<%= f.select :last_menstrual_period_weeks,
options_for_select(weeks_options, patient.last_menstrual_period_weeks ),
label: t('patient.dashboard.weeks_along'),
autocomplete: 'off',
help: t('patient.dashboard.currently', weeks: patient.last_menstrual_period_now_weeks, days: patient.last_menstrual_period_now_days) %>
</div>

<div class="col mt-4">
<%= f.select :last_menstrual_period_days,
options_for_select(days_options, patient.last_menstrual_period_days),
autocomplete: 'off',
skip_label: true,
help: t('patient.dashboard.called_on', date: patient.initial_call_date.strftime("%m/%d/%Y")) %>
<%= f.label :last_menstrual_period_days, t('common.days_along'), class: "sr-only" %>
</div>

<div class="col-3">
<%= f.date_field :appointment_date,
label: t('patient.shared.appt_date'),
autocomplete: 'off',
help: t('patient.dashboard.approx_gestation', weeks: patient.last_menstrual_period_at_appt_weeks, days: patient.last_menstrual_period_at_appt_days) %>
</div>
</div>

<div class="row">
<div class="col-4">
<%= f.text_field :primary_phone,
value: patient.primary_phone_display,
label: t('patient.dashboard.phone'),
autocomplete: 'off' %>
</div>

<div class="col">
<%= f.text_field :pronouns,
value: patient.pronouns,
autocomplete: 'off' %>
</div>

<div class="col">
<div class="form-group">
<label for="status"><%= t 'patient.shared.status' %> <%= tooltip_shell status_help_text(patient) %></label>
<input type="text" value="<%= patient.status %>" class="form-control form-control-plaintext" id="patient_status_display" autocomplete="off" disabled>
</div>
</div>

<div class="col-3">
<% if current_user.admin? %>
<div class="form-group">
<label for="admin-delete"><%= t 'patient.dashboard.delete_label' %></label>
<div>
<%= link_to t('patient.dashboard.delete'),
patient_path(patient),
class: 'btn btn-danger',
method: :delete,
data: { confirm: t('patient.dashboard.confirm_del', name: patient.name) } %>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
<%= render ReactComponent.new("PatientDashboardForm", raw_props: {
patient: patient.as_json,
weeksOptions: weeks_options.map { |opt| { label: opt[0], value: opt[1] } },
daysOptions: days_options.map { |opt| { label: opt[0], value: opt[1] } },
initialCallDate: patient.initial_call_date.strftime("%m/%d/%Y"),
statusHelpText: status_help_text(patient),
isAdmin: current_user.admin?,
patientPath: patient_path(patient),
formAuthenticityToken: form_authenticity_token
}) %>
</div>
6 changes: 0 additions & 6 deletions test/system/update_patient_info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class UpdatePatientInfoTest < ApplicationSystemTestCase
describe 'updating name' do
before do
fill_in 'First and last name', with: 'Susie Everyteen 2'
click_away_from_field
wait_for_ajax
reload_page_and_click_link 'Patient Information'
end
Expand Down Expand Up @@ -75,7 +74,6 @@ class UpdatePatientInfoTest < ApplicationSystemTestCase
describe 'updating appointment date' do
before do
fill_in 'Appointment date', with: 5.days.from_now.strftime('%m/%d/%Y')
click_away_from_field
wait_for_ajax
reload_page_and_click_link 'Patient Information'
end
Expand Down Expand Up @@ -108,7 +106,6 @@ class UpdatePatientInfoTest < ApplicationSystemTestCase
describe 'updating phone number' do
before do
fill_in 'Phone number', with: '123-666-8888'
click_away_from_field
wait_for_ajax
reload_page_and_click_link 'Patient Information'
end
Expand All @@ -123,7 +120,6 @@ class UpdatePatientInfoTest < ApplicationSystemTestCase
describe 'updating pronouns' do
before do
fill_in 'Pronouns', with: 'they/them'
click_away_from_field
wait_for_ajax
reload_page_and_click_link 'Patient Information'
end
Expand Down Expand Up @@ -298,7 +294,6 @@ class UpdatePatientInfoTest < ApplicationSystemTestCase

it 'should flash failure on a bad field change' do
fill_in 'Phone number', with: '111-222-3333445'
click_away_from_field
assert has_text? 'Primary phone is the wrong length'
end
end
Expand Down Expand Up @@ -365,7 +360,6 @@ class UpdatePatientInfoTest < ApplicationSystemTestCase
private

def reload_page_and_click_link(link_text)
click_away_from_field
visit authenticated_root_path
visit edit_patient_path @patient
click_link link_text
Expand Down
Loading