2024-06-24 18:16:55 -04:00
|
|
|
import axios from "axios";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
|
|
|
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
2024-08-25 17:35:46 -04:00
|
|
|
import { Label } from "@/components/ui/label";
|
2024-06-24 18:16:55 -04:00
|
|
|
import { Maximize2, Minimize2, Trash2Icon } from "lucide-react";
|
|
|
|
import { ActionType } from "@prisma/client";
|
2024-08-25 17:35:46 -04:00
|
|
|
import { boolean, z } from "zod";
|
2024-06-24 18:16:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
const actionTypes = [
|
|
|
|
{
|
|
|
|
"name": "Overwrite local file content",
|
2024-08-14 16:33:40 -04:00
|
|
|
"value": ActionType.WRITE_TO_FILE,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "File path",
|
|
|
|
"key": "file_path",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Enter local file path, relative or full.",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "File content",
|
|
|
|
"key": "file_content",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Enter the text to write to the file.",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
2024-06-24 18:16:55 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Append to local file",
|
2024-08-14 16:33:40 -04:00
|
|
|
"value": ActionType.APPEND_TO_FILE,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "File path",
|
|
|
|
"key": "file_path",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Enter local file path, relative or full.",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "File content",
|
|
|
|
"key": "file_content",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Enter the text to append to the file.",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
2024-06-24 18:16:55 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Cause a transformation on OBS scene item",
|
2024-08-14 16:33:40 -04:00
|
|
|
"value": ActionType.OBS_TRANSFORM,
|
|
|
|
"inputs": []
|
2024-06-24 18:16:55 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Play an audio file locally",
|
2024-08-14 16:33:40 -04:00
|
|
|
"value": ActionType.AUDIO_FILE,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "File path",
|
|
|
|
"key": "file_path",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Enter local file path, relative or full.",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "User gets a random TTS voice that is enabled",
|
|
|
|
"value": ActionType.RANDOM_TTS_VOICE,
|
|
|
|
"inputs": []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "User gets a specific TTS voice",
|
|
|
|
"value": ActionType.SPECIFIC_TTS_VOICE,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "TTS Voice",
|
|
|
|
"key": "tts_voice",
|
|
|
|
"placeholder": "Name of an enabled TTS voice",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Toggle OBS scene item visibility",
|
|
|
|
"value": ActionType.TOGGLE_OBS_VISIBILITY,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "Scene Name",
|
|
|
|
"key": "scene_name",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Name of the OBS scene",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "Scene Item Name",
|
|
|
|
"key": "scene_item_name",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Name of the OBS scene item / source",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Set OBS scene item visibility",
|
|
|
|
"value": ActionType.SPECIFIC_OBS_VISIBILITY,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "Scene Name",
|
|
|
|
"key": "scene_name",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Name of the OBS scene",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "Scene Item Name",
|
|
|
|
"key": "scene_item_name",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Name of the OBS scene item / source",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "text-values",
|
|
|
|
"label": "Visible",
|
|
|
|
"key": "obs_visible",
|
|
|
|
"placeholder": "true for visible; false otherwise",
|
2024-08-25 17:35:46 -04:00
|
|
|
"values": ["true", "false"],
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Set OBS scene item's index",
|
|
|
|
"value": ActionType.SPECIFIC_OBS_INDEX,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "Scene Name",
|
|
|
|
"key": "scene_name",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Name of the OBS scene",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "text",
|
|
|
|
"label": "Scene Item Name",
|
|
|
|
"key": "scene_item_name",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "Name of the OBS scene item / source",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "number",
|
|
|
|
"label": "Index",
|
|
|
|
"key": "obs_index",
|
2024-08-25 17:35:46 -04:00
|
|
|
"placeholder": "index, starting from 0.",
|
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Sleep - do nothing",
|
|
|
|
"value": ActionType.SLEEP,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "number",
|
|
|
|
"label": "Sleep",
|
|
|
|
"key": "sleep",
|
|
|
|
"placeholder": "Time in milliseconds to do nothing",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Nightbot - Play",
|
|
|
|
"value": ActionType.NIGHTBOT_PLAY,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "oauth.nightbot.play",
|
|
|
|
"label": "nightbot.play",
|
|
|
|
"key": "nightbot_play",
|
|
|
|
"placeholder": "",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Nightbot - Pause",
|
|
|
|
"value": ActionType.NIGHTBOT_PAUSE,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "oauth.nightbot.pause",
|
|
|
|
"label": "nightbot.pause",
|
|
|
|
"key": "nightbot_pause",
|
|
|
|
"placeholder": "",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Nightbot - Skip",
|
|
|
|
"value": ActionType.NIGHTBOT_SKIP,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "oauth.nightbot.skip",
|
|
|
|
"label": "nightbot.skip",
|
|
|
|
"key": "nightbot_skip",
|
|
|
|
"placeholder": "",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Nightbot - Clear Playlist",
|
|
|
|
"value": ActionType.NIGHTBOT_CLEAR_PLAYLIST,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "oauth.nightbot.clear_playlist",
|
|
|
|
"label": "nightbot.clear_playlist",
|
|
|
|
"key": "nightbot_clear_playlist",
|
|
|
|
"placeholder": "",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Nightbot - Clear Queue",
|
|
|
|
"value": ActionType.NIGHTBOT_CLEAR_QUEUE,
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"type": "oauth.nightbot.clear_queue",
|
|
|
|
"label": "nightbot.clear_queue",
|
|
|
|
"key": "nightbot_clear_queue",
|
|
|
|
"placeholder": "",
|
2024-08-25 17:35:46 -04:00
|
|
|
"required": true
|
2024-08-14 16:33:40 -04:00
|
|
|
}
|
|
|
|
]
|
2024-06-24 18:16:55 -04:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-08-25 17:35:46 -04:00
|
|
|
const nameSchema = z.string({
|
|
|
|
required_error: "Name is required.",
|
|
|
|
invalid_type_error: "Name must be a string"
|
|
|
|
}).regex(/^[\w\-\s]{1,32}$/, "Name must contain only letters, numbers, spaces, dashes, and underscores.")
|
2024-06-24 18:16:55 -04:00
|
|
|
|
|
|
|
interface RedeemableAction {
|
|
|
|
name: string
|
|
|
|
type: string | undefined
|
|
|
|
data: { [key: string]: string }
|
|
|
|
edit?: boolean
|
|
|
|
showEdit?: boolean
|
|
|
|
isNew: boolean
|
|
|
|
obsTransformations: { label: string, placeholder: string, description: string }[]
|
2024-08-14 16:33:40 -04:00
|
|
|
connections: { name: string, type: string }[]
|
2024-06-24 18:16:55 -04:00
|
|
|
adder: (name: string, type: ActionType, data: { [key: string]: string }) => void
|
|
|
|
remover: (action: { name: string, type: string, data: any }) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const RedemptionAction = ({
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
data,
|
|
|
|
edit,
|
|
|
|
showEdit = true,
|
|
|
|
isNew = false,
|
|
|
|
obsTransformations = [],
|
2024-08-14 16:33:40 -04:00
|
|
|
connections = [],
|
2024-06-24 18:16:55 -04:00
|
|
|
adder,
|
|
|
|
remover
|
|
|
|
}: RedeemableAction) => {
|
2024-08-14 16:33:40 -04:00
|
|
|
const [open, setOpen] = useState<{ [key: string]: boolean }>({ 'actions': false, 'oauth': false, 'oauth.nightbot': false, 'oauth.twitch': false })
|
2024-06-24 18:16:55 -04:00
|
|
|
const [actionName, setActionName] = useState(name)
|
2024-08-14 16:33:40 -04:00
|
|
|
const [actionType, setActionType] = useState<{ name: string, value: ActionType, inputs: any[] } | undefined>(actionTypes.find(a => a.value == type?.toUpperCase()))
|
2024-06-24 18:16:55 -04:00
|
|
|
const [actionData, setActionData] = useState<{ [key: string]: string }>(data)
|
|
|
|
const [isEditable, setIsEditable] = useState(edit)
|
|
|
|
const [isMinimized, setIsMinimized] = useState(!isNew)
|
|
|
|
const [oldData, setOldData] = useState<{ n: string, t: ActionType | undefined, d: { [k: string]: string } } | undefined>(undefined)
|
2024-08-25 17:35:46 -04:00
|
|
|
const [error, setError] = useState<string | undefined>(undefined)
|
2024-06-24 18:16:55 -04:00
|
|
|
|
2024-08-25 17:35:46 -04:00
|
|
|
function Save(isNew: boolean) {
|
|
|
|
setError(undefined)
|
|
|
|
if (!actionName) {
|
|
|
|
setError("Name is required.")
|
2024-06-24 18:16:55 -04:00
|
|
|
return
|
|
|
|
}
|
2024-08-25 17:35:46 -04:00
|
|
|
const nameValidation = nameSchema.safeParse(actionName)
|
|
|
|
if (!nameValidation.success) {
|
|
|
|
setError(JSON.parse(nameValidation.error['message'])[0].message)
|
2024-06-24 18:16:55 -04:00
|
|
|
return
|
|
|
|
}
|
2024-08-25 17:35:46 -04:00
|
|
|
if (!actionType) {
|
|
|
|
setError("Action type is required.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (!actionTypes.some(t => t.value == actionType.value)) {
|
|
|
|
setError("Invalid action type given.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (!actionData) {
|
|
|
|
setError("Something went wrong with the data.")
|
2024-06-24 18:16:55 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-08-25 17:35:46 -04:00
|
|
|
const inputs = actionTypes.find(a => a.value == actionType.value && a.name == actionType.name)!.inputs
|
|
|
|
const required = inputs.filter(i => i.required)
|
|
|
|
for (const input of required) {
|
|
|
|
if (!(input.key in actionData)) {
|
|
|
|
setError("The field '" + input.label + "' is required.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:16:55 -04:00
|
|
|
let info: any = {
|
2024-08-25 17:35:46 -04:00
|
|
|
name: actionName,
|
|
|
|
type: actionType.value,
|
2024-06-24 18:16:55 -04:00
|
|
|
}
|
|
|
|
|
2024-08-25 17:35:46 -04:00
|
|
|
info.data = actionData
|
2024-06-24 18:16:55 -04:00
|
|
|
|
|
|
|
if (isNew) {
|
|
|
|
axios.post("/api/settings/redemptions/actions", info)
|
|
|
|
.then(d => {
|
2024-08-25 17:35:46 -04:00
|
|
|
adder(actionName, actionType.value, actionData)
|
2024-06-24 18:16:55 -04:00
|
|
|
setActionName("")
|
|
|
|
setActionType(undefined)
|
|
|
|
setActionData({})
|
|
|
|
})
|
2024-08-25 17:35:46 -04:00
|
|
|
.catch(error => setError(error.response.data.message))
|
2024-06-24 18:16:55 -04:00
|
|
|
} else {
|
|
|
|
axios.put("/api/settings/redemptions/actions", info)
|
|
|
|
.then(d => {
|
|
|
|
setIsEditable(false)
|
|
|
|
})
|
2024-08-25 17:35:46 -04:00
|
|
|
.catch(error => setError(error.response.data.message))
|
2024-06-24 18:16:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-14 16:33:40 -04:00
|
|
|
function Cancel(data: { n: string, t: ActionType | undefined, d: { [k: string]: any } } | undefined) {
|
2024-08-25 17:35:46 -04:00
|
|
|
setError(undefined)
|
2024-06-24 18:16:55 -04:00
|
|
|
if (!data)
|
|
|
|
return
|
|
|
|
|
|
|
|
setActionName(data.n)
|
|
|
|
setActionType(actionTypes.find(a => a.value == data.t))
|
|
|
|
setActionData(data.d)
|
|
|
|
setIsEditable(false)
|
|
|
|
setOldData(undefined)
|
|
|
|
}
|
|
|
|
|
|
|
|
function Delete() {
|
2024-08-25 17:35:46 -04:00
|
|
|
axios.delete("/api/settings/redemptions/actions?action_name=" + actionName)
|
2024-06-24 18:16:55 -04:00
|
|
|
.then(d => {
|
|
|
|
remover(d.data)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="bg-orange-300 p-3 border-2 border-orange-400 rounded-lg w-[830px]">
|
|
|
|
{isMinimized &&
|
|
|
|
<div
|
|
|
|
className="flex">
|
|
|
|
<Label
|
|
|
|
className="mr-2 grow text-lg align-middle"
|
|
|
|
htmlFor="name">
|
|
|
|
{actionName}
|
|
|
|
</Label>
|
|
|
|
<Button
|
2024-08-14 16:33:40 -04:00
|
|
|
className="flex self-end"
|
2024-06-24 18:16:55 -04:00
|
|
|
onClick={e => setIsMinimized(!isMinimized)}>
|
|
|
|
{isMinimized ? <Maximize2 /> : <Minimize2 />}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
|| !isMinimized &&
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
className="pb-3">
|
|
|
|
<Label
|
|
|
|
className="mr-2"
|
|
|
|
htmlFor="name">
|
|
|
|
Action name
|
|
|
|
</Label>
|
|
|
|
<Input
|
|
|
|
className="inline-block w-[300px]"
|
|
|
|
id="name"
|
|
|
|
placeholder="Enter a name for this action"
|
|
|
|
onChange={e => setActionName(e.target.value)}
|
|
|
|
value={actionName}
|
|
|
|
readOnly={!isNew} />
|
|
|
|
<Label
|
|
|
|
className="ml-10 mr-2"
|
|
|
|
htmlFor="type">
|
|
|
|
Action type
|
|
|
|
</Label>
|
|
|
|
{!isEditable &&
|
|
|
|
<Input
|
|
|
|
className="inline-block w-[300px] justify-between"
|
|
|
|
name="type"
|
|
|
|
value={actionType?.name}
|
|
|
|
readOnly />
|
|
|
|
|| isEditable &&
|
|
|
|
<Popover
|
2024-08-14 16:33:40 -04:00
|
|
|
open={open['actions']}
|
|
|
|
onOpenChange={() => setOpen({ ...open, 'actions': !open['actions'] })}>
|
2024-06-24 18:16:55 -04:00
|
|
|
<PopoverTrigger asChild>
|
|
|
|
<Button
|
|
|
|
variant="outline"
|
|
|
|
role="combobox"
|
2024-08-14 16:33:40 -04:00
|
|
|
aria-expanded={open['actions']}
|
2024-06-24 18:16:55 -04:00
|
|
|
className="w-[300px] justify-between"
|
|
|
|
>{!actionType ? "Select one..." : actionType.name}</Button>
|
|
|
|
</PopoverTrigger>
|
|
|
|
<PopoverContent>
|
|
|
|
<Command>
|
|
|
|
<CommandInput
|
|
|
|
placeholder="Filter actions..."
|
|
|
|
autoFocus={true} />
|
|
|
|
<CommandList>
|
|
|
|
<CommandEmpty>No action found.</CommandEmpty>
|
|
|
|
<CommandGroup>
|
|
|
|
{actionTypes.map((action) => (
|
|
|
|
<CommandItem
|
|
|
|
value={action.name}
|
|
|
|
key={action.value}
|
|
|
|
onSelect={(value) => {
|
|
|
|
setActionType(actionTypes.find(v => v.name.toLowerCase() == value.toLowerCase()))
|
2024-08-14 16:33:40 -04:00
|
|
|
setOpen({ ...open, 'actions': false })
|
2024-06-24 18:16:55 -04:00
|
|
|
}}>
|
|
|
|
{action.name}
|
|
|
|
</CommandItem>
|
|
|
|
))}
|
|
|
|
</CommandGroup>
|
|
|
|
</CommandList>
|
|
|
|
</Command>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div>
|
2024-08-14 16:33:40 -04:00
|
|
|
{actionType &&
|
2024-06-24 18:16:55 -04:00
|
|
|
<div>
|
2024-08-14 16:33:40 -04:00
|
|
|
{actionType.inputs.map(i => {
|
|
|
|
if (i.type == "text") {
|
|
|
|
return <div key={i.key} className="mt-3">
|
|
|
|
<Label
|
|
|
|
className="mr-2"
|
|
|
|
htmlFor={i.key}>
|
|
|
|
{i.label}
|
|
|
|
</Label>
|
|
|
|
<Input
|
|
|
|
className="w-[300px] justify-between inline-block"
|
|
|
|
name={i.key}
|
|
|
|
placeholder={i.placeholder}
|
|
|
|
value={actionData[i.key]}
|
|
|
|
onChange={e => setActionData(d => {
|
|
|
|
let abc = { ...actionData }
|
|
|
|
abc[i.key] = e.target.value;
|
|
|
|
return abc
|
|
|
|
})}
|
|
|
|
readOnly={!isEditable} />
|
|
|
|
</div>
|
|
|
|
} else if (i.type == "number") {
|
|
|
|
return <div key={i.key} className="mt-3">
|
|
|
|
<Label
|
|
|
|
className="mr-2"
|
|
|
|
htmlFor={i.key}>
|
|
|
|
{i.label}
|
|
|
|
</Label>
|
|
|
|
<Input
|
|
|
|
className="w-[300px] justify-between inline-block"
|
|
|
|
name={i.key}
|
|
|
|
placeholder={i.placeholder}
|
|
|
|
value={actionData[i.key]}
|
|
|
|
onChange={e => setActionData(d => {
|
|
|
|
let abc = { ...actionData }
|
|
|
|
const v = parseInt(e.target.value)
|
2024-08-25 17:35:46 -04:00
|
|
|
if (e.target.value.length == 0 || Number.isNaN(v)) {
|
2024-08-14 16:33:40 -04:00
|
|
|
abc[i.key] = "0"
|
|
|
|
} else if (!Number.isNaN(v) && Number.isSafeInteger(v)) {
|
|
|
|
abc[i.key] = v.toString()
|
|
|
|
}
|
|
|
|
return abc
|
|
|
|
})}
|
|
|
|
readOnly={!isEditable} />
|
|
|
|
</div>
|
|
|
|
} else if (i.type == "text-values") {
|
|
|
|
return <div key={i.key} className="mt-3">
|
|
|
|
<Label
|
|
|
|
className="mr-2"
|
|
|
|
htmlFor={i.key}>
|
|
|
|
{i.label}
|
|
|
|
</Label>
|
|
|
|
<Input
|
|
|
|
className="w-[300px] justify-between inline-block"
|
|
|
|
name={i.key}
|
|
|
|
placeholder={i.placeholder}
|
|
|
|
value={actionData[i.key]}
|
|
|
|
onChange={e => setActionData(d => {
|
|
|
|
let abc = { ...actionData }
|
|
|
|
abc[i.key] = i.values.map((v: string) => v.startsWith(e.target.value)).some((v: boolean) => v) ? e.target.value : abc[i.key]
|
|
|
|
return abc
|
|
|
|
})}
|
|
|
|
readOnly={!isEditable} />
|
|
|
|
</div>
|
|
|
|
} else {
|
|
|
|
return <div key={i.key}>
|
|
|
|
<Label
|
|
|
|
className="mr-2"
|
|
|
|
htmlFor={i.key}>
|
|
|
|
Connection
|
|
|
|
</Label>
|
|
|
|
<Popover
|
|
|
|
open={open[i.type]}
|
|
|
|
onOpenChange={() => { const temp = { ...open }; temp[i.type] = !temp[i.type]; setOpen(temp) }}>
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
<Button
|
|
|
|
variant="outline"
|
|
|
|
role="combobox"
|
|
|
|
aria-expanded={open[i.type]}
|
|
|
|
className="w-[300px] justify-between"
|
|
|
|
>{!('oauth_name' in actionData) ? "Select connection..." : actionData.oauth_name}</Button>
|
|
|
|
</PopoverTrigger>
|
|
|
|
<PopoverContent>
|
|
|
|
<Command>
|
|
|
|
<CommandInput
|
|
|
|
placeholder="Search connections..."
|
|
|
|
autoFocus={true} />
|
|
|
|
<CommandList>
|
|
|
|
<CommandEmpty>No connection found.</CommandEmpty>
|
|
|
|
<CommandGroup>
|
|
|
|
{connections.filter(c => !i.type.includes('.') || c.type == i.type.split('.')[1])
|
|
|
|
.map((connection) => (
|
|
|
|
<CommandItem
|
|
|
|
value={connection.name}
|
|
|
|
key={connection.name}
|
|
|
|
onSelect={(value) => {
|
|
|
|
const connection = connections.find(v => v.name.toLowerCase() == value.toLowerCase())
|
|
|
|
if (!!connection) {
|
|
|
|
setActionData({
|
|
|
|
'oauth_name': connection.name,
|
2024-08-25 17:35:46 -04:00
|
|
|
'oauth_type': connection.type
|
2024-08-14 16:33:40 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setActionData({})
|
|
|
|
|
|
|
|
const temp = { ...open }
|
|
|
|
temp[i.type] = false
|
|
|
|
setOpen(temp)
|
|
|
|
}}>
|
|
|
|
{connection.name}
|
|
|
|
</CommandItem>
|
|
|
|
))}
|
|
|
|
</CommandGroup>
|
|
|
|
</CommandList>
|
|
|
|
</Command>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
})}
|
2024-06-24 18:16:55 -04:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{actionType && actionType.value == ActionType.OBS_TRANSFORM &&
|
|
|
|
<div>
|
|
|
|
{obsTransformations.map(t =>
|
|
|
|
<div
|
2024-08-14 16:33:40 -04:00
|
|
|
key={t.label.toLowerCase()}
|
2024-06-24 18:16:55 -04:00
|
|
|
className="mt-3">
|
|
|
|
<Label
|
|
|
|
className="mr-2"
|
|
|
|
htmlFor={t.label.toLowerCase()}>
|
|
|
|
{t.label.split("_").map(w => w.substring(0, 1).toUpperCase() + w.substring(1).toLowerCase()).join(" ")}
|
|
|
|
</Label>
|
|
|
|
<Input
|
|
|
|
className="w-[300px] justify-between inline-block"
|
|
|
|
name={t.label.toLowerCase()}
|
|
|
|
placeholder={t.placeholder}
|
|
|
|
value={actionData[t.label]}
|
|
|
|
onChange={e => {
|
|
|
|
let c = { ...actionData }
|
|
|
|
c[t.label] = e.target.value
|
|
|
|
setActionData(c)
|
|
|
|
}}
|
|
|
|
readOnly={!isEditable} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
2024-08-25 17:35:46 -04:00
|
|
|
{error &&
|
|
|
|
<div className="text-red-600 font-bold">
|
|
|
|
{error}
|
|
|
|
</div>
|
|
|
|
}
|
2024-06-24 18:16:55 -04:00
|
|
|
<div>
|
|
|
|
{isEditable &&
|
|
|
|
<Button
|
|
|
|
className="m-3"
|
2024-08-25 17:35:46 -04:00
|
|
|
onClick={() => Save(isNew)}>
|
2024-06-24 18:16:55 -04:00
|
|
|
{isNew ? "Add" : "Save"}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
{isEditable && !isNew &&
|
|
|
|
<Button
|
|
|
|
className="m-3"
|
|
|
|
onClick={() => Cancel(oldData)}>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
{showEdit && !isEditable &&
|
|
|
|
<Button
|
|
|
|
className="m-3"
|
|
|
|
onClick={() => {
|
|
|
|
setOldData({ n: actionName, t: actionType?.value, d: actionData })
|
|
|
|
setIsEditable(true)
|
|
|
|
}}>
|
|
|
|
Edit
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
{!isEditable &&
|
|
|
|
<Button
|
|
|
|
className="m-3 bg-red-500 hover:bg-red-600 align-bottom"
|
|
|
|
onClick={() => Delete()}>
|
|
|
|
<Trash2Icon />
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
{!isNew &&
|
|
|
|
<Button
|
|
|
|
className="m-3 align-middle"
|
|
|
|
onClick={e => setIsMinimized(!isMinimized)}>
|
|
|
|
{isMinimized ? <Maximize2 /> : <Minimize2 />}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RedemptionAction;
|