feat: add enter to submit
This commit is contained in:
@@ -18,13 +18,28 @@ interface ListItemStore {
|
|||||||
|
|
||||||
setNewStageValue: (newStageValue: string) => void
|
setNewStageValue: (newStageValue: string) => void
|
||||||
setIsAddingStage: (isAddingStage: boolean) => void
|
setIsAddingStage: (isAddingStage: boolean) => void
|
||||||
|
addStage: (entryName: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const useListItemStore = create<ListItemStore>()((set) => ({
|
const useListItemStore = create<ListItemStore>()((set, get) => ({
|
||||||
isAddingStage: false,
|
isAddingStage: false,
|
||||||
newStageValue: "",
|
newStageValue: "",
|
||||||
|
|
||||||
setNewStageValue: (newStageValue: string) => set({ newStageValue }),
|
setNewStageValue: (newStageValue: string) => set({ newStageValue }),
|
||||||
setIsAddingStage: (isAddingStage: boolean) => set({ isAddingStage }),
|
setIsAddingStage: (isAddingStage: boolean) => set({ isAddingStage }),
|
||||||
|
addStage: (entryName) => {
|
||||||
|
const store = useStore.getState()
|
||||||
|
let stage = get().newStageValue
|
||||||
|
if (stage) {
|
||||||
|
if (stage === DEFAULT_NODE.acceptedNode.key.toLowerCase()) {
|
||||||
|
stage = DEFAULT_NODE.acceptedNode.key
|
||||||
|
} else if (stage === DEFAULT_NODE.rejectedNode.key.toLowerCase()) {
|
||||||
|
stage = DEFAULT_NODE.rejectedNode.key
|
||||||
|
}
|
||||||
|
store.addStageInEntry(stage, entryName)
|
||||||
|
set({ isAddingStage: false, newStageValue: "" })
|
||||||
|
}
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const EntryContext = createContext<Entry>(null as unknown as Entry)
|
const EntryContext = createContext<Entry>(null as unknown as Entry)
|
||||||
@@ -79,14 +94,22 @@ function NewStageInput() {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
function ActualStageInput() {
|
function ActualStageInput() {
|
||||||
|
const entry = useContext(EntryContext)
|
||||||
const newStageValue = useListItemStore((state) => state.newStageValue)
|
const newStageValue = useListItemStore((state) => state.newStageValue)
|
||||||
const setNewStageValue = useListItemStore((state) => state.setNewStageValue)
|
const setNewStageValue = useListItemStore((state) => state.setNewStageValue)
|
||||||
|
const addStage = useListItemStore((state) => state.addStage)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
value={newStageValue}
|
value={newStageValue}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setNewStageValue(event.currentTarget.value)
|
setNewStageValue(event.currentTarget.value)
|
||||||
}}
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
addStage(entry.name)
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="bg-transparent"
|
className="bg-transparent"
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -159,21 +182,10 @@ const DefaultActions = memo(() => {
|
|||||||
const AddStageActions = memo(() => {
|
const AddStageActions = memo(() => {
|
||||||
const entry = useContext(EntryContext)
|
const entry = useContext(EntryContext)
|
||||||
const setIsAddingStage = useListItemStore((state) => state.setIsAddingStage)
|
const setIsAddingStage = useListItemStore((state) => state.setIsAddingStage)
|
||||||
const setNewStageValue = useListItemStore((state) => state.setNewStageValue)
|
const addStage = useListItemStore((state) => state.addStage)
|
||||||
const addStageToEntry = useStore((state) => state.addStageInEntry)
|
|
||||||
|
|
||||||
function onOk() {
|
function onOk() {
|
||||||
let stage = useListItemStore.getState().newStageValue
|
addStage(entry.name)
|
||||||
if (stage) {
|
|
||||||
if (stage === DEFAULT_NODE.acceptedNode.key.toLowerCase()) {
|
|
||||||
stage = DEFAULT_NODE.acceptedNode.key
|
|
||||||
} else if (stage === DEFAULT_NODE.rejectedNode.key.toLowerCase()) {
|
|
||||||
stage = DEFAULT_NODE.rejectedNode.key
|
|
||||||
}
|
|
||||||
addStageToEntry(stage, entry.name)
|
|
||||||
setIsAddingStage(false)
|
|
||||||
setNewStageValue("")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCancel() {
|
function onCancel() {
|
||||||
|
@@ -116,6 +116,11 @@ function AddApplicationForm() {
|
|||||||
className="px-2"
|
className="px-2"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Application name"
|
placeholder="Application name"
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === "Enter") {
|
||||||
|
onAddButtonClick()
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="flex flex-row space-x-2 mt-2">
|
<div className="flex flex-row space-x-2 mt-2">
|
||||||
|
Reference in New Issue
Block a user