Skip to content

Commit

Permalink
task/WP-742: Fix renew registration in react (#362)
Browse files Browse the repository at this point in the history
* Strip trailing slash from reg_id coming from submitter reg listing to get to renew form

* Renew form hookup fixes: change type for useRegFormData function to capture all data passed from view + index reg year up by 1 on form population to match prod behavior

* Update apcd-cms/src/apps/registrations/views.py

Co-authored-by: Chandra Y <[email protected]>

---------

Co-authored-by: Chandra Y <[email protected]>
  • Loading branch information
edmondsgarrett and chandra-tacc authored Nov 18, 2024
1 parent 1eb5210 commit d67dfd9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apcd-cms/src/apps/registrations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RegistrationFormView(TemplateView):
def get(self, request):
formatted_reg_data = []
renew = False
reg_id = request.GET.get('reg_id', None)
reg_id = request.GET.get('reg_id', None).rstrip('/') # reg_id coming from renew has trailing slash appended, need to remove to pass correct request through
if reg_id and (has_groups(request.user, ['APCD_ADMIN', 'SUBMITTER_ADMIN'])):
try:
response = get_submitter_code(request.user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const RegistrationForm: React.FC<{
validateOnMount={true}
initialValues={
data
? transformToRegistrationFormValues(data)
? transformToRegistrationFormValues(data['registration_data'], data['renew'])
: inputValues ?? initialValues
}
initialTouched={initialTouched}
Expand Down
7 changes: 3 additions & 4 deletions apcd-cms/src/client/src/hooks/registrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type RegFormData = {
registration_data: RegistrationRow;
registration_data: RegistrationContent;
renew: boolean;
};

Expand Down Expand Up @@ -110,18 +110,17 @@ export type RegistrationFormValues = {
};

export function transformToRegistrationFormValues(
registration: RegistrationContent
registration: RegistrationContent, renew?: boolean | undefined
): RegistrationFormValues {

const typeValueMap:Record<string, string> = { // to set database value for field rather than display value
'Insurance Carrier': 'carrier',
'Plan Administrator¹ (TPA/ASO)': 'tpa_aso',
'Pharmacy Benefit Manager (PBM)': 'pbm'
}

return {
on_behalf_of: registration.for_self?.toString() ?? '',
reg_year: registration.year.toString(),
reg_year: (registration.year + (renew ? 1 : 0)).toString(),
type: registration.type ? typeValueMap[registration.type] : '',
business_name: registration.biz_name,
mailing_address: registration.address,
Expand Down
4 changes: 2 additions & 2 deletions apcd-cms/src/client/src/hooks/registrations/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const getRegFormData = async (reg_id: string | null) => {

export const useRegFormData = (
reg_id: string | null
): UseQueryResult<RegistrationContent> => {
): UseQueryResult<RegFormData> => {
const query = useQuery(['reg_form', reg_id], () => getRegFormData(reg_id), {
enabled: !!reg_id,
}) as UseQueryResult<RegistrationContent>;
}) as UseQueryResult<RegFormData>;

return { ...query };
};
Expand Down

0 comments on commit d67dfd9

Please sign in to comment.