@@ -19,7 +19,7 @@ import { useFormik } from "formik";
1919import { Fragment , useCallback , useEffect , useMemo , useState } from "react" ;
2020import ReactMarkdown from "react-markdown" ;
2121import { v4 } from "uuid" ;
22- import { InferType , boolean , mixed , object , string } from "yup" ;
22+ import { InferType , array , boolean , mixed , object , string } from "yup" ;
2323import { track } from "../../utils/analytics" ;
2424import { useUserData } from "../../utils/useUser" ;
2525import { PrimaryButton } from "../core/buttons.component" ;
@@ -40,9 +40,9 @@ export const NewPostSchema = object().shape({
4040 . required ( "Content cannot be empty" )
4141 . min ( 2 , "Content too Short!" )
4242 . max ( 9669 , "Content too Long!" ) ,
43- type : mixed < PostType > ( )
44- . oneOf ( Object . values ( PostType ) )
45- . required ( "Enter valid type " ) ,
43+ tags : array ( )
44+ . of ( mixed < PostType > ( ) . oneOf ( Object . values ( PostType ) ) )
45+ . required ( "Enter valid tags " ) ,
4646 status : mixed < PostStatus > ( )
4747 . oneOf ( Object . values ( PostStatus ) )
4848 . required ( "Enter valid status" ) ,
@@ -120,7 +120,7 @@ export default function PostFormComponent({
120120 initialValues : {
121121 title : "" ,
122122 content : "" ,
123- type : Object . keys ( PostType ) [ 0 ] as PostType ,
123+ tags : [ Object . keys ( PostType ) [ 0 ] ] as PostType [ ] ,
124124 status : PostStatus . published ,
125125 page_id : "" ,
126126 images_folder : "" ,
@@ -201,21 +201,29 @@ export default function PostFormComponent({
201201 < div className = "overflow-hidden md:rounded-md md:border border-gray-300 dark:border-gray-700 shadow-sm focus-within:border-indigo-500 focus-within:ring-1 focus-within:ring-indigo-500" >
202202 < Listbox
203203 as = "div"
204- value = { formik . values . type }
205- onChange = { ( type ) => formik . setFieldValue ( "type" , type ) }
204+ multiple
205+ value = { formik . values . tags }
206+ onChange = { ( tags ) => {
207+ formik . setFieldValue ( "tags" , tags ) ;
208+ if ( ! tags . length ) {
209+ formik . setFieldValue ( "tags" , [ Object . keys ( PostType ) [ 0 ] ] ) ;
210+ }
211+ } }
206212 className = "flex-shrink-0 bg-white dark:bg-gray-900 p-2"
207213 >
208- { ( { open } ) => (
214+ { ( { open, value } ) => (
209215 < >
210216 < Listbox . Label className = "sr-only" >
211217 { " " }
212218 Add a label{ " " }
213219 </ Listbox . Label >
214220 < div className = "relative" >
215- < Listbox . Button className = "relative p-0 pl-1 scale-110" >
216- < PostTypeBadge
217- type = { formik . values . type ?? PostType . fix }
218- />
221+ < Listbox . Button className = "relative p-0 pl-1 scale-110 w-auto text-left" >
222+ { value . map ( ( tag : PostType ) => (
223+ < div key = { tag } className = "inline-block ml-2" >
224+ < PostTypeBadge type = { tag } />
225+ </ div >
226+ ) ) }
219227 </ Listbox . Button >
220228
221229 < Transition
@@ -241,6 +249,12 @@ export default function PostFormComponent({
241249 >
242250 < div className = "flex items-center" >
243251 < span className = "block truncate font-medium" >
252+ { value . includes ( label ) ? (
253+ < CheckIcon
254+ className = "h-5 w-5 inline mr-2"
255+ aria-hidden = "true"
256+ />
257+ ) : null }
244258 { PostTypeToLabel [ label ] }
245259 </ span >
246260 </ div >
0 commit comments