Skip to content

Commit

Permalink
feat: disappearing status
Browse files Browse the repository at this point in the history
Signed-off-by: Azanul <azanulhaque@gmail.com>
  • Loading branch information
Azanul committed Jun 8, 2024
1 parent 4468906 commit 10e6425
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions frontend/src/components/WuphfForm.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { sendWuphf } from '../features/wuphf/wuphfSlice';

type Props = { chatId: string }
type Props = { chatId: string };

const WuphfForm: React.FC<Props> = (props) => {
const dispatch = useDispatch();
const [message, setMessage] = useState('');
const [status, setStatus] = useState('');

useEffect(() => {
if (status) {
const timer = setTimeout(() => {
setStatus('');
}, 3000);
return () => clearTimeout(timer);
}
}, [status]);

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
Expand All @@ -23,7 +32,7 @@ const WuphfForm: React.FC<Props> = (props) => {
if (response.ok) {
setStatus('Message sent successfully');
setMessage('');
dispatch(sendWuphf({chatId: props.chatId, message: message}));
dispatch(sendWuphf({ chatId: props.chatId, message: message }));
} else {
setStatus('Failed to send message');
}
Expand Down

0 comments on commit 10e6425

Please sign in to comment.