All files / components/ChatMessage ChatMessageCreate.js

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39              8x               8x 1x     8x             8x 1x     8x                
 
import ChatMessageForm from "main/components/ChatMessage/ChatMessageForm";
import { useBackendMutation } from "main/utils/useBackend";
import { toast } from "react-toastify";
 
export default function RideRequestCreatePage() {
 
    const objectToAxiosParams = (chatMessage) => ({
        url: "/api/chat/post",
        method: "POST",
        params: {
            content: chatMessage.content
        }
    });
 
    const onSuccess = () => {
        toast('Message sent');
    }
 
    const mutation = useBackendMutation(
        objectToAxiosParams,
        { onSuccess },
        // Stryker disable next-line all : hard to set up test for caching
        ["/api/chat/get"]
    );
 
    const onSubmit = async (data) => {
        mutation.mutate(data);
    }
 
    return (
        
        <div className="pt-2">
            <h1>Send</h1>
            <ChatMessageForm submitAction={onSubmit} />
        </div>
        
    )
}