minor tweaks of manalink form (#647)
* minor tweaks of manalink form, adding M$ in front of amount and changing expire time to dropdown instead of calendar selection * made minimum for uses and amount 1, it seems otherwise it does not generate a link at all
This commit is contained in:
parent
44d993a588
commit
2f02e4d3e0
|
@ -63,15 +63,39 @@ function CreateManalinkForm(props: {
|
||||||
const [finishedCreating, setFinishedCreating] = useState(false)
|
const [finishedCreating, setFinishedCreating] = useState(false)
|
||||||
const [copyPressed, setCopyPressed] = useState(false)
|
const [copyPressed, setCopyPressed] = useState(false)
|
||||||
setTimeout(() => setCopyPressed(false), 300)
|
setTimeout(() => setCopyPressed(false), 300)
|
||||||
|
const defaultExpire = 'week'
|
||||||
|
const [expiresIn, setExpiresIn] = useState(defaultExpire)
|
||||||
|
|
||||||
const [newManalink, setNewManalink] = useState<ManalinkInfo>({
|
const [newManalink, setNewManalink] = useState<ManalinkInfo>({
|
||||||
expiresTime: null,
|
expiresTime: dayjs().add(1, defaultExpire).valueOf(),
|
||||||
amount: 100,
|
amount: 100,
|
||||||
maxUses: 1,
|
maxUses: 1,
|
||||||
uses: 0,
|
uses: 0,
|
||||||
message: '',
|
message: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const EXPIRE_OPTIONS = {
|
||||||
|
day: '1 Day',
|
||||||
|
week: '1 Week',
|
||||||
|
month: '1 Month',
|
||||||
|
never: 'Never',
|
||||||
|
}
|
||||||
|
|
||||||
|
const expireOptions = Object.entries(EXPIRE_OPTIONS).map(([key, value]) => {
|
||||||
|
return <option value={key}>{value}</option>
|
||||||
|
})
|
||||||
|
|
||||||
|
function setExpireTime(timeDelta: string) {
|
||||||
|
const expiresTime =
|
||||||
|
timeDelta === 'never' ? null : dayjs().add(1, timeDelta).valueOf()
|
||||||
|
setNewManalink((m) => {
|
||||||
|
return {
|
||||||
|
...m,
|
||||||
|
expiresTime,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!finishedCreating && (
|
{!finishedCreating && (
|
||||||
|
@ -87,23 +111,30 @@ function CreateManalinkForm(props: {
|
||||||
<div className="flex flex-col flex-wrap gap-x-5 gap-y-2">
|
<div className="flex flex-col flex-wrap gap-x-5 gap-y-2">
|
||||||
<div className="form-control flex-auto">
|
<div className="form-control flex-auto">
|
||||||
<label className="label">Amount</label>
|
<label className="label">Amount</label>
|
||||||
<input
|
<div className="relative">
|
||||||
className="input input-bordered"
|
<span className="absolute mx-3 mt-3.5 text-sm text-gray-400">
|
||||||
type="number"
|
M$
|
||||||
value={newManalink.amount}
|
</span>
|
||||||
onChange={(e) =>
|
<input
|
||||||
setNewManalink((m) => {
|
className="input input-bordered w-full pl-10"
|
||||||
return { ...m, amount: parseInt(e.target.value) }
|
type="number"
|
||||||
})
|
min="1"
|
||||||
}
|
value={newManalink.amount}
|
||||||
></input>
|
onChange={(e) =>
|
||||||
|
setNewManalink((m) => {
|
||||||
|
return { ...m, amount: parseInt(e.target.value) }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2 md:flex-row">
|
<div className="flex flex-col gap-2 md:flex-row">
|
||||||
<div className="form-control">
|
<div className="form-control w-full md:w-1/2">
|
||||||
<label className="label">Uses</label>
|
<label className="label">Uses</label>
|
||||||
<input
|
<input
|
||||||
className="input input-bordered w-full"
|
className="input input-bordered"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="1"
|
||||||
value={newManalink.maxUses ?? ''}
|
value={newManalink.maxUses ?? ''}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setNewManalink((m) => {
|
setNewManalink((m) => {
|
||||||
|
@ -112,29 +143,19 @@ function CreateManalinkForm(props: {
|
||||||
}
|
}
|
||||||
></input>
|
></input>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-control">
|
<div className="form-control w-full md:w-1/2">
|
||||||
<label className="label">Expires in</label>
|
<label className="label">Expires in</label>
|
||||||
<input
|
<select
|
||||||
value={
|
className="!select !select-bordered"
|
||||||
newManalink.expiresTime != null
|
value={expiresIn}
|
||||||
? dayjs(newManalink.expiresTime).format(
|
defaultValue={defaultExpire}
|
||||||
'YYYY-MM-DDTHH:mm'
|
|
||||||
)
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
className="input input-bordered"
|
|
||||||
type="datetime-local"
|
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setNewManalink((m) => {
|
setExpiresIn(e.target.value)
|
||||||
return {
|
setExpireTime(e.target.value)
|
||||||
...m,
|
|
||||||
expiresTime: e.target.value
|
|
||||||
? dayjs(e.target.value, 'YYYY-MM-DDTHH:mm').valueOf()
|
|
||||||
: null,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
></input>
|
>
|
||||||
|
{expireOptions}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-control w-full">
|
<div className="form-control w-full">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user