fixing flow to make sure that failures don't clear form

This commit is contained in:
talksik
2022-06-11 13:18:05 -05:00
parent 41ca22bc5d
commit f01f490819
3 changed files with 12 additions and 5 deletions
@@ -21,7 +21,7 @@ interface IConversationContext {
selectedConversation?: MasterConversation;
selectConversation?: (conversationId: string, temporaryOverrideSort?: boolean) => Promise<void>;
handleStartConversation?: (otherUsers: User[], conversationName?: string) => Promise<void>;
handleStartConversation?: (otherUsers: User[], conversationName?: string) => Promise<boolean>;
}
const ConversationContext = React.createContext<IConversationContext>({
@@ -139,10 +139,13 @@ export function ConversationProvider({ children }: { children: React.ReactNode }
selectConversation(createdConversationResult.data.conversationId.toString(), true);
toast.success('started conversation');
return true;
} catch (error) {
console.error(error);
toast.error(error.message);
}
return false;
},
[selectConversation],
);
@@ -97,11 +97,13 @@ export default function NewConversationDialog() {
setIsSubmitting(true);
await handleStartConversation(selectedUsers, conversationName);
const succeeded = await handleStartConversation(selectedUsers, conversationName);
// clear form for next time
setSelectedUsers([]);
setConversationName('');
if (succeeded) {
setSelectedUsers([]);
setConversationName('');
}
setIsSubmitting(false);
}, [
+3 -1
View File
@@ -35,7 +35,9 @@ export default function Terminal() {
>
<Navbar />
<ConversationList />
<Box sx={{ p: 2 }}>
<ConversationList />
</Box>
</Grid>
<Grid item xs={8} sx={{ bgcolor: 'white' }}>