Skip to content

Commit 42f7ec3

Browse files
committed
fix: better destination enabling
1 parent 7f9365a commit 42f7ec3

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

lib/components/Destination.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Typography, TextField, Box } from "@mui/material"
2-
import { Public, Android, PhoneIphone } from "@mui/icons-material"
1+
import { Typography, TextField, Box, IconButton } from "@mui/material"
2+
import { Public, Android, PhoneIphone, Delete } from "@mui/icons-material"
33

44
export interface DestinationProps {
55
platform: "web" | "ios" | "android"
66
value: string
77
onChange: (value: string) => void
8+
onRemove: () => void
89
}
910

10-
export const Destination = ({ platform, value, onChange }: DestinationProps) => {
11-
11+
export const Destination = ({ platform, value, onChange, onRemove }: DestinationProps) => {
1212
const PlatformIcon = () => {
1313
switch (platform) {
1414
case "web":
@@ -23,8 +23,13 @@ export const Destination = ({ platform, value, onChange }: DestinationProps) =>
2323
return (
2424
<Box m={1}>
2525
<Box display="flex" alignItems="center" justifyContent="space-between">
26-
<Typography variant="subtitle2">Platform: {platform}</Typography>
27-
<PlatformIcon />
26+
<Box display="flex" alignItems="center" gap={1}>
27+
<PlatformIcon />
28+
<Typography variant="subtitle2">Platform: {platform}</Typography>
29+
</Box>
30+
<IconButton onClick={onRemove}>
31+
<Delete />
32+
</IconButton>
2833
</Box>
2934

3035
{platform === "web" && <Web value={value} onChange={onChange} />}
@@ -34,7 +39,6 @@ export const Destination = ({ platform, value, onChange }: DestinationProps) =>
3439
)
3540
}
3641

37-
3842
const Web = ({ value, onChange }: { value: string, onChange: (value: string) => void }) => {
3943
return (
4044
<TextField

lib/components/LinkConfig/EditModal.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ export interface EditModalProps {
2525
}
2626

2727
const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
28-
console.log("config", config)
2928
const [name, setName] = useState(config?.name || "")
3029
const [seoTitle, setSeoTitle] = useState(config?.seo?.title || "")
3130
const [seoDescription, setSeoDescription] = useState(config?.seo?.description || "")
3231
const [seoMedia, setSeoMedia] = useState(config?.seo?.media || "")
3332
const [webDestValue, setWebDestValue] = useState(config?.destinations?.find(dest => dest.platform === "web")?.value || "")
33+
const [webEnabled, setWebEnabled] = useState(!!config?.destinations?.find(dest => dest.platform === "web")?.value)
3434
const [iosDestValue, setIosDestValue] = useState(config?.destinations?.find(dest => dest.platform === "ios")?.value || "")
35+
const [iosEnabled, setIosEnabled] = useState(!!config?.destinations?.find(dest => dest.platform === "ios")?.value)
3536
const [androidDestValue, setAndroidDestValue] = useState(config?.destinations?.find(dest => dest.platform === "android")?.value || "")
37+
const [androidEnabled, setAndroidEnabled] = useState(!!config?.destinations?.find(dest => dest.platform === "android")?.value)
3638

3739
const [error, setError] = useState("")
3840
const [isLoading, setIsLoading] = useState(false)
@@ -152,14 +154,13 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
152154

153155
<Box my={2}>
154156
<Typography variant="subtitle1">Destinations</Typography>
155-
{/* todo: better check here */}
156-
{!webDestValue && <IconButton onClick={() => setWebDestValue("https://")}><Public color="primary" /></IconButton>}
157-
{!iosDestValue && <IconButton onClick={() => setIosDestValue("https://")}><PhoneIphone color="primary" /></IconButton>}
158-
{!androidDestValue && <IconButton onClick={() => setAndroidDestValue("https://")}><Android color="primary" /></IconButton>}
159-
160-
{webDestValue && <Destination platform="web" value={webDestValue} onChange={val => setWebDestValue(val)} />}
161-
{iosDestValue && <Destination platform="ios" value={iosDestValue} onChange={val => setIosDestValue(val)} />}
162-
{androidDestValue && <Destination platform="android" value={androidDestValue} onChange={val => setAndroidDestValue(val)} />}
157+
{!webEnabled && <IconButton onClick={() => { setWebEnabled(true); setWebDestValue("https://") }}><Public color="primary" /></IconButton>}
158+
{!iosEnabled && <IconButton onClick={() => { setIosEnabled(true); setIosDestValue("https://") }}><PhoneIphone color="primary" /></IconButton>}
159+
{!androidEnabled && <IconButton onClick={() => { setAndroidEnabled(true); setAndroidDestValue("https://") }}><Android color="primary" /></IconButton>}
160+
161+
{(webDestValue || webEnabled) && <Destination platform="web" value={webDestValue} onRemove={() => { setWebEnabled(false); setWebDestValue("") }} onChange={val => setWebDestValue(val)} />}
162+
{(iosDestValue || iosEnabled) && <Destination platform="ios" value={iosDestValue} onRemove={() => { setIosEnabled(false); setIosDestValue("") }} onChange={val => setIosDestValue(val)} />}
163+
{(androidDestValue || androidEnabled) && <Destination platform="android" value={androidDestValue} onRemove={() => { setAndroidEnabled(false); setAndroidDestValue("") }} onChange={val => setAndroidDestValue(val)} />}
163164

164165
</Box>
165166

0 commit comments

Comments
 (0)