fix: use dropdown instead of switch

This commit is contained in:
ShubhamPalriwala
2024-05-31 09:24:39 +05:30
parent 89eff65124
commit 862e0437e7
3 changed files with 89 additions and 77 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 131 KiB

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 110 KiB

@@ -21,7 +21,6 @@ import {
SecretInput, SecretInput,
Select, Select,
SelectItem, SelectItem,
Switch
} from "@app/components/v2"; } from "@app/components/v2";
import { useOrganization } from "@app/context"; import { useOrganization } from "@app/context";
import { useTimedReset } from "@app/hooks"; import { useTimedReset } from "@app/hooks";
@@ -62,7 +61,8 @@ const expirationUnitsAndActions = [
]; ];
const schema = yup.object({ const schema = yup.object({
value: yup.string().max(1000).required().label("Shared Secret Value"), value: yup.string().max(10000).required().label("Shared Secret Value"),
expiryOption: yup.string().optional().label("Expiration Option").default("Time"),
expiresAfterViews: yup.number().min(1).optional().label("Expires After Views"), expiresAfterViews: yup.number().min(1).optional().label("Expires After Views"),
expiresInValue: yup.number().min(1).optional().label("Expiration Value"), expiresInValue: yup.number().min(1).optional().label("Expiration Value"),
expiresInUnit: yup.string().optional().label("Expiration Unit") expiresInUnit: yup.string().optional().label("Expiration Unit")
@@ -90,7 +90,7 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
const createSharedSecret = useCreateSharedSecret(); const createSharedSecret = useCreateSharedSecret();
const { currentOrg } = useOrganization(); const { currentOrg } = useOrganization();
const [newSharedSecret, setnewSharedSecret] = useState(""); const [newSharedSecret, setnewSharedSecret] = useState("");
const [expiryOption, setExpiryOption] = useState<"time" | "views">("time"); const [expiryOption, setExpiryOption] = useState<"Time" | "Views">("Time");
const hasSharedSecret = Boolean(newSharedSecret); const hasSharedSecret = Boolean(newSharedSecret);
const [isUrlCopied, , setIsUrlCopied] = useTimedReset<boolean>({ const [isUrlCopied, , setIsUrlCopied] = useTimedReset<boolean>({
initialState: false initialState: false
@@ -134,8 +134,8 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
iv, iv,
tag, tag,
hashedHex, hashedHex,
expiresAt: expiryOption === "time" ? expiresAt : undefined, expiresAt: expiryOption === "Time" ? expiresAt : undefined,
expiresAfterViews: expiryOption === "views" ? expiresAfterViews : undefined expiresAfterViews: expiryOption === "Views" ? expiresAfterViews : undefined
}); });
setnewSharedSecret( setnewSharedSecret(
`${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent( `${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent(
@@ -197,26 +197,37 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
</FormControl> </FormControl>
)} )}
/> />
<div> <div className="flex w-full flex-row">
<p className="mb-2 flex items-center text-sm font-normal text-mineshaft-400"> <div className="flex w-1/5">
Set Expiry Based On <Controller
</p> control={control}
<div className="mb-4 flex w-full flex-row justify-start"> name="expiryOption"
<p className="mb-0.5 mr-1 flex items-center text-sm font-normal text-mineshaft-400"> defaultValue="Time"
Time render={({ field: { onChange, ...field }, fieldState: { error } }) => (
</p> <FormControl
<Switch label="Expire On"
id="expiryOption" errorText={error?.message}
onCheckedChange={(value) => setExpiryOption(value ? "views" : "time")} isError={Boolean(error)}
isChecked={expiryOption === "views"} >
<Select
defaultValue={field.value}
{...field}
onValueChange={(e: "Time" | "Views") => setExpiryOption(e)}
value={expiryOption}
className="w-full"
>
{["Time", "Views"].map((unit) => (
<SelectItem value={unit} key={unit}>
{unit}
</SelectItem>
))}
</Select>
</FormControl>
)}
/> />
<p className="mb-0.5 ml-3 flex items-center text-sm font-normal text-mineshaft-400">
Views
</p>
</div> </div>
</div> <div className="flex w-4/5">
<div> {expiryOption === "Views" ? (
{expiryOption === "views" ? (
<Controller <Controller
control={control} control={control}
name="expiresAfterViews" name="expiresAfterViews"
@@ -233,7 +244,7 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
)} )}
/> />
) : ( ) : (
<div className="flex w-full flex-row justify-end"> <div className="flex w-full">
<div className="w-3/5"> <div className="w-3/5">
<Controller <Controller
control={control} control={control}
@@ -280,6 +291,7 @@ export const AddShareSecretModal = ({ popUp, handlePopUpToggle }: Props) => {
</div> </div>
)} )}
</div> </div>
</div>
<div className="flex items-center"> <div className="flex items-center">
<Button <Button
className="mr-4" className="mr-4"