Skip to content

Commit

Permalink
more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed May 17, 2024
1 parent ef521d0 commit 1fbf0cf
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions examples/crm/src/contacts/ContactInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const ContactInputs = () => {
const [create] = useCreate();
const { identity } = useGetIdentity();
const notify = useNotify();
const handleCreateCompany = (companyName?: string) => {
const handleCreateCompany = async (companyName?: string) => {
if (!companyName) return;
return new Promise<Company>((resolve, reject) => {
create(
try {
const newCompany = await create(
'companies',
{
data: {
Expand All @@ -41,17 +41,15 @@ export const ContactInputs = () => {
created_at: new Date().toISOString(),
},
},
{
onSuccess: resolve,
onError: (error: Error) => {
notify('An error occurred while creating the company', {
type: 'error',
});
reject(error);
},
}
{ returnPromise: true }
);
});
return newCompany;
} catch (error) {
notify('An error occurred while creating the company', {
type: 'error',
});
throw error;
}
};
return (
<Box flex="1" mt={-1}>
Expand Down

0 comments on commit 1fbf0cf

Please sign in to comment.