Fakultas Ilmu Komputer UI

Commit 977a55d7 authored by jonathanchandra15's avatar jonathanchandra15
Browse files

add error handling when create/edit thread

parent 201be242
This diff is collapsed.
......@@ -12,6 +12,7 @@ export default function FormCreateThread(props){
const { value: topicId, bind: bindTopicId, reset: resetTopicId } = useInput(0)
const [listTopic, setlistTopic] = useState([]);
const userId = AuthService.getCurrentUserId()
const [message, setMessage] = useState('')
useEffect(() => {
async function getListTopic() {
......@@ -39,11 +40,11 @@ export default function FormCreateThread(props){
if (a.id > b.id) return -1
return 0
});
const thisThreads = usersThreads[0]
props.redirect(`/topic/${thisThreads.topic_name}/${thisThreads.id}`)
const thisThreads = usersThreads[0];
props.redirect(`/topic/${thisThreads.topic_name}/${thisThreads.id}`);
}
catch(error){
setMessage("Thread title already exist in the selected topic")
}
resetBody();
resetTitle();
......@@ -51,23 +52,32 @@ export default function FormCreateThread(props){
}
return (
<form onSubmit={handleSubmit}>
<div className="form_container">
<label for="title">Title</label>
<input type='text' className="title" name="title" placeholder="Your threads title" required="false" {...bindTitle}/>
<label>Topic</label>
<select className="topic" name="topic" required="false" {...bindTopicId}>
<option value=""></option>
{listTopic.map((topic) => (
<option value={topic.id}>{topic.name}</option>
))}
</select>
<label for="body">Body</label>
<textarea className="body" name="body" placeholder="Tulis" required="false" {...bindBody}/>
<div className="buttonContainer">
<input type="submit" className="buttonSubmit" value="Create Thread"/>
<div>
{message && (
<div>
<div className='alert alert-danger' role='alert'>
{message}
</div>
</div>
)}
<form onSubmit={handleSubmit}>
<div className="form_container">
<label for="title">Title</label>
<input type='text' className="title" name="title" placeholder="Your threads title" required="false" {...bindTitle}/>
<label>Topic</label>
<select className="topic" name="topic" required="false" {...bindTopicId}>
<option value=""></option>
{listTopic.map((topic) => (
<option value={topic.id}>{topic.name}</option>
))}
</select>
<label for="body">Body</label>
<textarea className="body" name="body" placeholder="Tulis" required="false" {...bindBody}/>
<div className="buttonContainer">
<input type="submit" className="buttonSubmit" value="Create Thread"/>
</div>
</div>
</form>
</div>
</form>
)
}
......@@ -11,6 +11,7 @@ export default function CreateThreadForm(props){
const { value: topicId, setValue: setTopicId, bind: bindTopicId, reset: resetTopicId } = useInput(0)
const [listTopic, setlistTopic] = useState([]);
const [point, setPoint] = useState(0);
const [message, setMessage] = useState('')
const threadIdParam = props.threadId
......@@ -49,7 +50,7 @@ export default function CreateThreadForm(props){
props.history.push(`/topic/${topic.name}/${threadIdParam}`)
}
catch(error){
setMessage("Thread title already exist in the selected topic")
}
resetBody();
resetTitle();
......@@ -57,23 +58,32 @@ export default function CreateThreadForm(props){
}
return (
<form onSubmit={handleSubmit}>
<div className="form_container">
<label for="title">Title</label>
<input type='text' className="title" name="title" placeholder="Your threads title" required="false" {...bindTitle}/>
<label>Topic</label>
<select className="topic" name="topic" required="false" {...bindTopicId}>
<option value=""></option>
{listTopic.map((topic) => (
<option value={topic.id}>{topic.name}</option>
))}
</select>
<label for="body">Body</label>
<textarea className="body" name="body" placeholder="Tulis" required="false" {...bindBody}/>
<div className="buttonContainer">
<input type="submit" className="buttonSubmit" value="Edit Thread"/>
<div>
{message && (
<div>
<div className='alert alert-danger' role='alert'>
{message}
</div>
</div>
</div>
</form>
)}
<form onSubmit={handleSubmit}>
<div className="form_container">
<label for="title">Title</label>
<input type='text' className="title" name="title" placeholder="Your threads title" required="false" {...bindTitle}/>
<label>Topic</label>
<select className="topic" name="topic" required="false" {...bindTopicId}>
<option value=""></option>
{listTopic.map((topic) => (
<option value={topic.id}>{topic.name}</option>
))}
</select>
<label for="body">Body</label>
<textarea className="body" name="body" placeholder="Tulis" required="false" {...bindBody}/>
<div className="buttonContainer">
<input type="submit" className="buttonSubmit" value="Edit Thread"/>
</div>
</div>
</form>
</div>
)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment