Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Changes can also be flagged with a GitHub label for tracking purposes. The URL o
- Extending read-only DB configuration [#7139](https://github.com/ethyca/fides/pull/7139)
- Removed the ManualTaskLog table since it is un-used. This is a lossy migration, it can be `downgraded` but data will not be restored. [#7124](https://github.com/ethyca/fides/pull/7124) https://github.com/ethyca/fides/labels/db-migration
- Renamed staged resource diff status from 'approved' to 'reviewed' in database migration [#7159](https://github.com/ethyca/fides/pull/7159) https://github.com/ethyca/fides/labels/db-migration
- Update the privacy request notification email template with new branding, improved copy, and enhanced UX in the notification configuration drawer. [#7192](https://github.com/ethyca/fides/pull/7124)

### Developer Experience
- Deprecated Chakra UI exports with `Chakra` prefix, removed `Ant` prefix from Ant Design exports [#7173](https://github.com/ethyca/fides/pull/7173)
Expand Down
2 changes: 1 addition & 1 deletion clients/admin-ui/src/features/auth/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useGetUserPermissionsQuery } from "~/features/user-management";

import { logout, selectToken, selectUser } from "./auth.slice";

const REDIRECT_IGNORES = ["/", "/login"];
const REDIRECT_IGNORES = ["/login"];

const useProtectedRoute = (redirectUrl: string) => {
const router = useRouter();
Expand Down
122 changes: 49 additions & 73 deletions clients/admin-ui/src/features/privacy-requests/EmailChipList.tsx
Original file line number Diff line number Diff line change
@@ -1,114 +1,90 @@
import {
ChakraFormControl as FormControl,
ChakraFormErrorMessage as FormErrorMessage,
ChakraFormLabel as FormLabel,
chakraForwardRef as forwardRef,
ChakraInput as Input,
ChakraTag as Tag,
ChakraTagCloseButton as TagCloseButton,
ChakraTagLabel as TagLabel,
ChakraVStack as VStack,
ChakraWrap as Wrap,
} from "fidesui";
import { FieldArrayRenderProps } from "formik";
import React, { useState } from "react";
import { Input, Tag } from "fidesui";
import React, { forwardRef, useState } from "react";

const EMAIL_REGEXP = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
const isValidEmail = (email: string) => EMAIL_REGEXP.test(email);

type EmailChipListProps = {
isRequired: boolean;
emails: string[];
onEmailsChange: (emails: string[]) => void;
disabled?: boolean;
};

const EmailChipList = forwardRef(
(
{
isRequired = false,
...props
}: FieldArrayRenderProps & EmailChipListProps,
ref,
) => {
const { emails }: { emails: string[] } = props.form.values;
const EmailChipList = forwardRef<HTMLInputElement, EmailChipListProps>(
({ emails, onEmailsChange, disabled = false }, ref) => {
const [inputValue, setInputValue] = useState("");

const emailChipExists = (email: string) => emails.includes(email);

const addEmails = (emailsToAdd: string[]) => {
if (disabled) return;
const validatedEmails = emailsToAdd
.map((e) => e.trim())
.filter((email) => isValidEmail(email) && !emailChipExists(email));
validatedEmails.forEach((email) => props.push(email));
setInputValue("");
if (validatedEmails.length > 0) {
onEmailsChange([...emails, ...validatedEmails]);
setInputValue("");
}
};

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (disabled) return;
setInputValue(event.target.value);
};

const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (disabled) return;
if (["Enter", "Tab", ","].includes(event.key)) {
event.preventDefault();
addEmails([inputValue]);
}
};

const handlePaste = (event: React.ClipboardEvent<HTMLInputElement>) => {
if (disabled) return;
event.preventDefault();
const pastedData = event.clipboardData.getData("text");
const pastedEmails = pastedData.split(",");
addEmails(pastedEmails);
};

const removeEmail = (emailToRemove: string) => {
if (disabled) return;
onEmailsChange(emails.filter((email) => email !== emailToRemove));
};

return (
<FormControl
alignItems="baseline"
display="inline-flex"
isInvalid={!!props.form.errors[props.name]}
isRequired={isRequired}
>
<FormLabel fontSize="md" htmlFor="email">
Email
</FormLabel>
<VStack align="flex-start" w="inherit">
<Input
autoComplete="off"
placeholder="Type or paste email addresses separated by commas and press `Enter` or `Tab`..."
onChange={handleChange}
onKeyDown={handleKeyDown}
onPaste={handlePaste}
ref={ref}
size="sm"
type="email"
value={inputValue}
/>
<FormErrorMessage>
{props.form.errors[props.name] as string}
</FormErrorMessage>
{emails.length > 0 && (
<Wrap spacing={1} mb={3} pt="8px">
{emails.map((email, index) => (
<Tag
key={email}
borderRadius="full"
backgroundColor="primary.400"
color="white"
size="sm"
variant="solid"
>
<TagLabel>{email}</TagLabel>
<TagCloseButton
onClick={() => {
props.remove(index);
}}
/>
</Tag>
))}
</Wrap>
)}
</VStack>
</FormControl>
<div className="w-full">
<Input
autoComplete="off"
placeholder="Enter one or more email addresses"
onChange={handleChange}
onKeyDown={handleKeyDown}
onPaste={handlePaste}
ref={ref}
type="email"
value={inputValue}
disabled={disabled}
/>
{emails.length > 0 && (
<div className="flex flex-wrap gap-2 mt-2">
{emails.map((email) => (
<Tag
key={email}
closable={!disabled}
onClose={() => removeEmail(email)}
color="default"
>
{email}
</Tag>
))}
</div>
)}
</div>
);
},
);

EmailChipList.displayName = "EmailChipList";

export default EmailChipList;
Loading
Loading