-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
754 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Badge from "@components/Badge"; | ||
import FullTooltip from "@components/FullTooltip"; | ||
import { GlobeIcon } from "lucide-react"; | ||
import * as React from "react"; | ||
|
||
type Props = { | ||
domains: string[]; | ||
}; | ||
export const DomainListBadge = ({ domains }: Props) => { | ||
const firstDomain = domains.length > 0 ? domains[0] : undefined; | ||
|
||
return ( | ||
<DomainsTooltip domains={domains}> | ||
<div className={"inline-flex items-center gap-2"}> | ||
{firstDomain && ( | ||
<Badge variant={"gray"}> | ||
<GlobeIcon size={10} /> | ||
{firstDomain} | ||
</Badge> | ||
)} | ||
{domains && domains.length > 1 && ( | ||
<Badge variant={"gray"}>+ {domains.length - 1}</Badge> | ||
)} | ||
</div> | ||
</DomainsTooltip> | ||
); | ||
}; | ||
|
||
export const DomainsTooltip = ({ | ||
domains, | ||
children, | ||
className, | ||
}: { | ||
domains: string[]; | ||
children: React.ReactNode; | ||
className?: string; | ||
}) => { | ||
return ( | ||
<FullTooltip | ||
interactive={false} | ||
className={className} | ||
content={ | ||
<div className={"flex flex-col gap-2 items-start"}> | ||
{domains.map((domain) => { | ||
return ( | ||
domain && ( | ||
<div | ||
key={domain} | ||
className={"flex gap-2 items-center justify-between w-full"} | ||
> | ||
<div | ||
className={ | ||
"flex gap-2 items-center text-nb-gray-300 text-xs" | ||
} | ||
> | ||
<GlobeIcon size={11} /> | ||
{domain} | ||
</div> | ||
</div> | ||
) | ||
); | ||
})} | ||
</div> | ||
} | ||
disabled={domains.length <= 1} | ||
> | ||
{children} | ||
</FullTooltip> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import Button from "@components/Button"; | ||
import { Input } from "@components/Input"; | ||
import { validator } from "@utils/helpers"; | ||
import { uniqueId } from "lodash"; | ||
import { GlobeIcon, MinusCircleIcon } from "lucide-react"; | ||
import * as React from "react"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
import { Domain } from "@/interfaces/Domain"; | ||
|
||
type Props = { | ||
value: Domain; | ||
onChange: (d: Domain) => void; | ||
onRemove: () => void; | ||
onError?: (error: boolean) => void; | ||
error?: string; | ||
}; | ||
enum ActionType { | ||
ADD = "ADD", | ||
REMOVE = "REMOVE", | ||
UPDATE = "UPDATE", | ||
} | ||
|
||
export const domainReducer = (state: Domain[], action: any): Domain[] => { | ||
switch (action.type) { | ||
case ActionType.ADD: | ||
return [...state, { name: "", id: uniqueId("domain") }]; | ||
case ActionType.REMOVE: | ||
return state.filter((_, i) => i !== action.index); | ||
case ActionType.UPDATE: | ||
return state.map((n, i) => (i === action.index ? action.d : n)); | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default function InputDomain({ | ||
value, | ||
onChange, | ||
onRemove, | ||
onError, | ||
}: Readonly<Props>) { | ||
const [name, setName] = useState(value?.name || ""); | ||
|
||
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setName(e.target.value); | ||
onChange({ ...value, name: e.target.value }); | ||
}; | ||
|
||
const domainError = useMemo(() => { | ||
if (name == "") { | ||
return ""; | ||
} | ||
const valid = validator.isValidDomain(name); | ||
if (!valid) { | ||
return "Please enter a valid domain, e.g. example.com or intra.example.com"; | ||
} | ||
}, [name]); | ||
|
||
useEffect(() => { | ||
const hasError = domainError !== "" && domainError !== undefined; | ||
onError?.(hasError); | ||
return () => onError?.(false); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [domainError]); | ||
|
||
return ( | ||
<div className={"flex gap-2 w-full"}> | ||
<div className={"w-full"}> | ||
<Input | ||
customPrefix={<GlobeIcon size={15} />} | ||
placeholder={"e.g., example.com"} | ||
maxWidthClass={"w-full"} | ||
value={name} | ||
error={domainError} | ||
onChange={handleNameChange} | ||
/> | ||
</div> | ||
|
||
<Button | ||
className={"h-[42px]"} | ||
variant={"default-outline"} | ||
onClick={onRemove} | ||
> | ||
<MinusCircleIcon size={15} /> | ||
</Button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.