Skip to content

Commit

Permalink
Handle IVA creation response properly (#199)
Browse files Browse the repository at this point in the history
* Properly handle IVA creation response object

* Fix IVA creation mock response
  • Loading branch information
Cito authored Jun 13, 2024
1 parent cf13b68 commit fa1061d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions src/components/profile/newIVAsModal/newIVAModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ const NewIVAModal = (props: NewIVAModalProps) => {
const response = await fetchJson(url, method, userData).catch(() => null);
if (response && response.status === ok) {
try {
const id = await response.text();
const newIVA: IVA = {
id: id,
type: userData.type as unknown as IVAType,
value: userData.value,
changed: new Date().toISOString(),
status: IVAStatus.Unverified,
};
props.newUserIVA(newIVA);
setPromptText("");
setClickedButton(null);
props.setShow(false);
const iva = await response.json();
const id = iva.id;
if (id) {
const newIVA: IVA = {
id,
type: userData.type as unknown as IVAType,
value: userData.value,
changed: new Date().toISOString(),
status: IVAStatus.Unverified,
};
props.newUserIVA(newIVA);
setPromptText("");
setClickedButton(null);
props.setShow(false);
}
} catch {}
}
setDisabledButton(false);
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const responses = {
"GET /api/auth/users/*/ivas": allIVAs.slice(1, 4),

// New IVA
"POST /api/auth/users/*/ivas": "TEST1234566789",
"POST /api/auth/users/*/ivas": {id: "TEST1234566789"},

// Delete IVA
"DELETE /api/auth/users/*/ivas/*": 204,
Expand Down

0 comments on commit fa1061d

Please sign in to comment.