@@ -12,7 +12,7 @@ import {
1212 CircularProgress ,
1313 Box ,
1414} from "@mui/material"
15- import { Close } from "@mui/icons-material"
15+ import { Android , Close , PhoneIphone , Public } from "@mui/icons-material"
1616
1717import { LinkConfig } from "@/lib/services/linkConfig"
1818import { ConfirmButton } from "../ConfirmButton"
@@ -30,7 +30,9 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
3030 const [ seoTitle , setSeoTitle ] = useState ( config ?. seo ?. title || "" )
3131 const [ seoDescription , setSeoDescription ] = useState ( config ?. seo ?. description || "" )
3232 const [ seoMedia , setSeoMedia ] = useState ( config ?. seo ?. media || "" )
33- const [ destinationValue , setDestinationValue ] = useState ( config ?. destinations ?. [ 0 ] ?. value || "" )
33+ const [ webDestValue , setWebDestValue ] = useState ( config ?. destinations ?. find ( dest => dest . platform === "web" ) ?. value || "" )
34+ const [ iosDestValue , setIosDestValue ] = useState ( config ?. destinations ?. find ( dest => dest . platform === "ios" ) ?. value || "" )
35+ const [ androidDestValue , setAndroidDestValue ] = useState ( config ?. destinations ?. find ( dest => dest . platform === "android" ) ?. value || "" )
3436
3537 const [ error , setError ] = useState ( "" )
3638 const [ isLoading , setIsLoading ] = useState ( false )
@@ -42,6 +44,29 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
4244 onClose && onClose ( )
4345 }
4446
47+ const buildDestinations = ( ) => {
48+ const destinations = [ ]
49+ if ( webDestValue ) {
50+ destinations . push ( {
51+ platform : "web" ,
52+ value : webDestValue ,
53+ } )
54+ }
55+ if ( iosDestValue ) {
56+ destinations . push ( {
57+ platform : "ios" ,
58+ value : iosDestValue ,
59+ } )
60+ }
61+ if ( androidDestValue ) {
62+ destinations . push ( {
63+ platform : "android" ,
64+ value : androidDestValue ,
65+ } )
66+ }
67+ return destinations
68+ }
69+
4570 const createNewConfig = async ( ) : Promise < string | undefined > => {
4671 try {
4772 const res = await fetch ( "/api/linkConfigs" , {
@@ -58,10 +83,7 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
5883 description : seoDescription || "" ,
5984 media : seoMedia || "" ,
6085 } ,
61- destinations : [ {
62- platform : "web" ,
63- value : destinationValue ,
64- } ] ,
86+ destinations : buildDestinations ( ) ,
6587 } ) ,
6688 } )
6789
@@ -102,7 +124,6 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
102124 setIsLoading ( false )
103125 }
104126
105-
106127 return (
107128 < Dialog open = { open } onClose = { handleClose } fullWidth >
108129 < AppBar sx = { { position : "relative" } } color = "transparent" elevation = { 0 } >
@@ -131,8 +152,14 @@ const EditModal = ({ open, onClose, config }: EditModalProps): JSX.Element => {
131152
132153 < Box my = { 2 } >
133154 < Typography variant = "subtitle1" > Destinations</ Typography >
134- { /* <Repeater onAdd, onRemove, items={config.destinations}, renderChild /> */ }
135- < Destination platform = "web" value = { destinationValue } onChange = { val => setDestinationValue ( val ) } />
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 ) } /> }
136163
137164 </ Box >
138165
0 commit comments