-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dashboard): Nv 5276 Subscriber UI overview tab #7632
Merged
+968
−9
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
00bab29
feat(dashboard): Implement edit subscriber functionality with routing…
BiswaViraj 8af66a6
feat(subscriber): Add subscriber fetching functionality and UI compon…
BiswaViraj 78c06bc
feat(subscriber): Implement patch subscriber functionality and update…
BiswaViraj 7e45fa7
feat(subscriber): Update subscriber schema to allow nullable email an…
BiswaViraj d21c9ac
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj 9748b27
refactor(subscriber): remove unused Skeleton import from subscriber o…
BiswaViraj 9081b3a
refactor(subscriber): simplify form submission handling in subscriber…
BiswaViraj 9e1009c
Merge branch 'next' into nv-5276-ui-overview-tab
ChmaraX f9e80bb
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj b6d286c
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj aea2725
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj ec6e009
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj 492b9f2
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj ff7e9a5
Merge branch 'next' into nv-5276-ui-overview-tab
BiswaViraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
133 changes: 133 additions & 0 deletions
133
apps/dashboard/src/components/primitives/phone-input.tsx
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,133 @@ | ||
import * as React from 'react'; | ||
import { CheckIcon, ChevronsUpDown } from 'lucide-react'; | ||
import * as RPNInput from 'react-phone-number-input'; | ||
import flags from 'react-phone-number-input/flags'; | ||
import { cn } from '@/utils/ui'; | ||
import { InputPure, InputRoot, InputWrapper } from './input'; | ||
import { Popover, PopoverContent, PopoverTrigger } from './popover'; | ||
import { Button } from './button'; | ||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from './command'; | ||
import { ScrollArea } from './scroll-area'; | ||
|
||
type PhoneInputProps = Omit<React.ComponentProps<'input'>, 'onChange' | 'value' | 'ref'> & | ||
Omit<RPNInput.Props<typeof RPNInput.default>, 'onChange'> & { | ||
onChange?: (value: RPNInput.Value) => void; | ||
}; | ||
|
||
const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> = React.forwardRef< | ||
React.ElementRef<typeof RPNInput.default>, | ||
PhoneInputProps | ||
>(({ className, onChange, ...props }, ref) => { | ||
return ( | ||
<RPNInput.default | ||
ref={ref} | ||
className={cn('flex', className)} | ||
flagComponent={FlagComponent} | ||
countrySelectComponent={CountrySelect} | ||
inputComponent={InputComponent} | ||
smartCaret={false} | ||
/** | ||
* Handles the onChange event. | ||
* | ||
* react-phone-number-input might trigger the onChange event as undefined | ||
* when a valid phone number is not entered. To prevent this, | ||
* the value is coerced to an empty string. | ||
* | ||
* @param {E164Number | undefined} value - The entered value | ||
*/ | ||
onChange={(value) => onChange?.(value || ('' as RPNInput.Value))} | ||
{...props} | ||
/> | ||
); | ||
}); | ||
PhoneInput.displayName = 'PhoneInput'; | ||
|
||
type CountryEntry = { label: string; value: RPNInput.Country | undefined }; | ||
|
||
type CountrySelectProps = { | ||
disabled?: boolean; | ||
value: RPNInput.Country; | ||
options: CountryEntry[]; | ||
onChange: (country: RPNInput.Country) => void; | ||
}; | ||
|
||
const CountrySelect = ({ disabled, value: selectedCountry, options: countryList, onChange }: CountrySelectProps) => { | ||
return ( | ||
<Popover> | ||
<PopoverTrigger asChild> | ||
<Button | ||
type="button" | ||
variant="secondary" | ||
mode="outline" | ||
className="flex h-9 gap-1 rounded-e-none rounded-s-lg border-r-0 px-3 focus:z-10" | ||
disabled={disabled} | ||
> | ||
<FlagComponent country={selectedCountry} countryName={selectedCountry} /> | ||
<ChevronsUpDown className={cn('-mr-2 size-4 opacity-50', disabled ? 'hidden' : 'opacity-100')} /> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="w-[300px] p-0"> | ||
<Command> | ||
<CommandInput placeholder="Search country..." /> | ||
<CommandList> | ||
<CommandEmpty>No country found.</CommandEmpty> | ||
<ScrollArea className="h-72"> | ||
<CommandGroup> | ||
{countryList.map(({ value, label }) => | ||
value ? ( | ||
<CountrySelectOption | ||
key={value} | ||
country={value} | ||
countryName={label} | ||
selectedCountry={selectedCountry} | ||
onChange={onChange} | ||
/> | ||
) : null | ||
)} | ||
</CommandGroup> | ||
</ScrollArea> | ||
</CommandList> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; | ||
|
||
const InputComponent = React.forwardRef<HTMLInputElement, React.ComponentProps<typeof InputPure>>( | ||
({ className, ...props }, ref) => ( | ||
<InputRoot size="2xs" className="rounded-s-none"> | ||
<InputWrapper className="flex h-full items-center p-2 py-1"> | ||
<InputPure className={cn('rounded-e-lg rounded-s-none', className)} ref={ref} {...props} /> | ||
</InputWrapper> | ||
</InputRoot> | ||
) | ||
); | ||
InputComponent.displayName = 'InputComponent'; | ||
|
||
interface CountrySelectOptionProps extends RPNInput.FlagProps { | ||
selectedCountry: RPNInput.Country; | ||
onChange: (country: RPNInput.Country) => void; | ||
} | ||
|
||
const CountrySelectOption = ({ country, countryName, selectedCountry, onChange }: CountrySelectOptionProps) => { | ||
return ( | ||
<CommandItem className="gap-2" onSelect={() => onChange(country)}> | ||
<FlagComponent country={country} countryName={countryName} /> | ||
<span className="flex-1 text-sm">{countryName}</span> | ||
<span className="text-foreground/50 text-sm">{`+${RPNInput.getCountryCallingCode(country)}`}</span> | ||
<CheckIcon className={`ml-auto size-4 ${country === selectedCountry ? 'opacity-100' : 'opacity-0'}`} /> | ||
</CommandItem> | ||
); | ||
}; | ||
|
||
const FlagComponent = ({ country, countryName }: RPNInput.FlagProps) => { | ||
const Flag = flags[country]; | ||
|
||
return ( | ||
<span className="bg-foreground/20 flex h-4 w-6 overflow-hidden rounded-sm [&_svg]:size-full" key={country}> | ||
{Flag ? <Flag title={countryName} /> : <span className="size-full rounded-sm bg-neutral-100" />} | ||
</span> | ||
); | ||
}; | ||
|
||
export { PhoneInput }; |
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,28 @@ | ||
import { z } from 'zod'; | ||
import { isValidPhoneNumber } from 'react-phone-number-input'; | ||
|
||
export const SubscriberFormSchema = z.object({ | ||
firstName: z.string().optional(), | ||
lastName: z.string().optional(), | ||
email: z.string().email().optional().nullable(), | ||
BiswaViraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
phone: z | ||
.string() | ||
.refine(isValidPhoneNumber, { message: 'Invalid phone number' }) | ||
.optional() | ||
.or(z.literal('')) | ||
.optional(), | ||
avatar: z.string().optional(), | ||
locale: z.string().optional(), | ||
timezone: z.string().optional(), | ||
data: z | ||
.string() | ||
.transform((str, ctx) => { | ||
try { | ||
return JSON.parse(str); | ||
} catch (e) { | ||
ctx.addIssue({ code: 'custom', message: 'Custom data must be valid JSON' }); | ||
return z.NEVER; | ||
} | ||
}) | ||
.optional(), | ||
}); |
62 changes: 62 additions & 0 deletions
62
apps/dashboard/src/components/subscribers/subscriber-drawer.tsx
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,62 @@ | ||
import { motion } from 'motion/react'; | ||
import { Sheet, SheetContentBase, SheetDescription, SheetPortal, SheetTitle } from '../primitives/sheet'; | ||
import { VisuallyHidden } from '../primitives/visually-hidden'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
const transitionSetting = { duration: 0.4 }; | ||
|
||
type SubscriberDrawerProps = PropsWithChildren<{ | ||
open: boolean; | ||
BiswaViraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}>; | ||
|
||
export function SubscriberDrawer({ children, open }: SubscriberDrawerProps) { | ||
const navigate = useNavigate(); | ||
|
||
const handleCloseSheet = () => { | ||
navigate(-1); | ||
}; | ||
|
||
return ( | ||
<Sheet modal={false} open={open}> | ||
<motion.div | ||
initial={{ | ||
opacity: 0, | ||
}} | ||
animate={{ | ||
opacity: 1, | ||
}} | ||
exit={{ | ||
opacity: 0, | ||
}} | ||
className="fixed inset-0 z-50 h-screen w-screen bg-black/20" | ||
transition={transitionSetting} | ||
/> | ||
<SheetPortal> | ||
<SheetContentBase asChild onInteractOutside={handleCloseSheet} onEscapeKeyDown={handleCloseSheet}> | ||
<motion.div | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this Sheet is reusable across multiple screens (Create workflows, create environment, etc...) the appearance and exit animation should be part of the Sheet and not redefined every time we use it. |
||
initial={{ | ||
x: '100%', | ||
}} | ||
animate={{ | ||
x: 0, | ||
}} | ||
exit={{ | ||
x: '100%', | ||
}} | ||
transition={transitionSetting} | ||
className={ | ||
'bg-background fixed inset-y-0 right-0 z-50 flex h-full w-3/4 flex-col border-l shadow-lg outline-none sm:max-w-[600px]' | ||
} | ||
> | ||
<VisuallyHidden> | ||
<SheetTitle /> | ||
<SheetDescription /> | ||
</VisuallyHidden> | ||
{children} | ||
</motion.div> | ||
</SheetContentBase> | ||
</SheetPortal> | ||
</Sheet> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this dropdown needs a bit of polishing around the paddings, borders on focus, and the search input; please talk to Naveen about how we can improve it.
![Screenshot 2025-02-04 at 00 22 28](https://private-user-images.githubusercontent.com/2607232/409319197-4f335f30-21d0-4d29-bd54-49bbde9ddbd8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMzI5MzIsIm5iZiI6MTczOTIzMjYzMiwicGF0aCI6Ii8yNjA3MjMyLzQwOTMxOTE5Ny00ZjMzNWYzMC0yMWQwLTRkMjktYmQ1NC00OWJiZGU5ZGRiZDgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMDAxMDMyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTFjNzBmMDI3YmQyZmJiOWNjYzJhNjMxYTU1NDJhMTc1ZWVkZmJmZGIzMzg0OWEzODY3ZDRjOWQyOTY5OTg5OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.SOvQtPBJdz704muWOFfR-Cd7WKjXVnhLyWx5qiLnCw4)