Skip to content
Snippets Groups Projects
Commit dca1560c authored by xaralis's avatar xaralis
Browse files

feat: disallow adding proposals by regp

parent 05654387
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import ErrorMessage from "components/ErrorMessage";
import MarkdownEditor from "components/mde/MarkdownEditor";
import { useActionState } from "hooks";
const AddPostForm = ({ className }) => {
const AddPostForm = ({ className, canAddProposal }) => {
const cardRef = useRef();
const editorRef = useRef();
const [expanded, setExpanded] = useState(false);
......@@ -34,16 +34,24 @@ const AddPostForm = ({ className }) => {
setExpanded(false);
}, [setExpanded]);
const onWrite = useCallback(() => {
if (!expanded) {
setExpanded(true);
setTimeout(() => {
if (editorRef.current && editorRef.current.finalRefs.textarea.current) {
editorRef.current.finalRefs.textarea.current.focus();
}
}, 0);
}
}, [setExpanded, expanded]);
const onWrite = useCallback(
(evt) => {
setShowAddConfirm(false);
if (!expanded) {
setExpanded(true);
setTimeout(() => {
if (
editorRef.current &&
editorRef.current.finalRefs.textarea.current
) {
editorRef.current.finalRefs.textarea.current.focus();
}
}, 0);
}
},
[setExpanded, expanded, setShowAddConfirm]
);
const hideAddConfirm = useCallback(() => {
setShowAddConfirm(false);
......@@ -88,7 +96,7 @@ const AddPostForm = ({ className }) => {
className,
"hover:elevation-16 transition duration-500",
{
"elevation-4 cursor-text": !expanded,
"elevation-4 cursor-text": !expanded && !showAddConfirm,
"lg:elevation-16 container-padding--zero lg:container-padding--auto": expanded,
}
);
......@@ -146,39 +154,41 @@ const AddPostForm = ({ className }) => {
]}
/>
<div
className="form-field"
onChange={(evt) => setType(evt.target.value)}
>
<div className="form-field__wrapper form-field__wrapper--freeform flex-col sm:flex-row">
<div className="radio form-field__control">
<label>
<input
type="radio"
name="postType"
value="post"
defaultChecked
/>
<span className="text-sm sm:text-base">
Přidávám <strong>běžný příspěvek</strong>
</span>
</label>
</div>
<div className="radio form-field__control ml-0 mt-4 sm:mt-0 sm:ml-4">
<label>
<input
type="radio"
name="postType"
value="procedure-proposal"
/>
<span className="text-sm sm:text-base">
Přidávám <strong>návrh postupu</strong>
</span>
</label>
{canAddProposal && (
<div
className="form-field"
onChange={(evt) => setType(evt.target.value)}
>
<div className="form-field__wrapper form-field__wrapper--freeform flex-col sm:flex-row">
<div className="radio form-field__control">
<label>
<input
type="radio"
name="postType"
value="post"
defaultChecked
/>
<span className="text-sm sm:text-base">
Přidávám <strong>běžný příspěvek</strong>
</span>
</label>
</div>
<div className="radio form-field__control ml-0 mt-4 sm:mt-0 sm:ml-4">
<label>
<input
type="radio"
name="postType"
value="procedure-proposal"
/>
<span className="text-sm sm:text-base">
Přidávám <strong>návrh postupu</strong>
</span>
</label>
</div>
</div>
</div>
</div>
)}
{type === "procedure-proposal" && (
<p className="alert alert--light text-sm">
......
......@@ -330,7 +330,7 @@ const Home = () => {
)}
{programEntry.discussionOpened &&
isAuthenticated &&
!user.isBanned && <AddPostForm className="mb-8" />}
!user.isBanned && <AddPostForm className="mb-8" canAddProposal={user.role === "member" || user.role === "chairman"} />}
<PostsContainer
className="container-padding--zero lg:container-padding--auto"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment