Skip to content

Commit

Permalink
fix button bubbling event and submitting form when save button not re…
Browse files Browse the repository at this point in the history
…ndered
  • Loading branch information
dpgraham4401 committed May 11, 2024
1 parent 6d47287 commit b30bad6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
48 changes: 17 additions & 31 deletions client/src/components/RcraProfile/RcraProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function RcraProfile({ profile }: ProfileViewProps) {
});

useEffect(() => {
// ToDo: invalidating tags should be done in the slice
dispatch(userApi.util?.invalidateTags(['rcrainfoProfile']));
}, [inProgress]);

Expand All @@ -48,6 +49,7 @@ export function RcraProfile({ profile }: ProfileViewProps) {

/** submitting the RcrainfoProfile form (RCRAInfo API ID, Key, username, etc.)*/
const onSubmit = (data: RcraProfileForm) => {
console.log('submitting form');
setProfileLoading(!profileLoading);
setEditable(!editable);
updateRcrainfoProfile({ username: profile.user, data: data });
Expand Down Expand Up @@ -107,37 +109,21 @@ export function RcraProfile({ profile }: ProfileViewProps) {
</Col>
</Row>
<Row>
<div className="mx-1 d-flex flex-row-reverse">
{!editable ? (
<>
<Button
className="mx-2"
variant="outline-info"
type="button"
onClick={() => {
setEditable(!editable);
}}
>
Edit
</Button>
</>
) : (
<>
<Button className="mx-2" variant="success" type="submit">
Save
</Button>
<Button
className="mx-2"
variant="danger"
onClick={() => {
setEditable(!editable);
reset();
}}
>
Cancel
</Button>
</>
)}
<div className="mx-1 d-flex flex-row justify-content-end">
<Button
className="mx-2"
variant={editable ? 'danger' : 'primary'}
type="button"
onClick={() => {
setEditable(!editable);
reset();
}}
>
{editable ? 'Cancel' : 'Edit'}
</Button>
<Button className="mx-2" disabled={!editable} variant="success" type="submit">
Save
</Button>
</div>
</Row>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion client/src/store/htApi.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const haztrakApi = createApi({
providesTags: ['code'],
}),
getOrgSites: build.query<Array<HaztrakSite>, string>({
query: (id) => ({ url: `org/${id}/site`, method: 'get' }),
query: (id) => ({ url: `org/${id}/sites`, method: 'get' }),
providesTags: ['site'],
}),
getUserHaztrakSites: build.query<Array<HaztrakSite>, void>({
Expand Down

0 comments on commit b30bad6

Please sign in to comment.