diff --git a/src/interface/web/app/automations/automations.module.css b/src/interface/web/app/automations/automations.module.css index 206d4c36..25b4b79f 100644 --- a/src/interface/web/app/automations/automations.module.css +++ b/src/interface/web/app/automations/automations.module.css @@ -4,6 +4,11 @@ div.automationsLayout { gap: 1rem; } +div.automationCard { + display: grid; + grid-template-rows: auto 1fr auto; +} + @media screen and (max-width: 768px) { div.automationsLayout { grid-template-columns: 1fr; diff --git a/src/interface/web/app/automations/page.tsx b/src/interface/web/app/automations/page.tsx index 85a0cb7d..52606781 100644 --- a/src/interface/web/app/automations/page.tsx +++ b/src/interface/web/app/automations/page.tsx @@ -47,8 +47,8 @@ import styles from './automations.module.css'; import ShareLink from '../components/shareLink/shareLink'; import { useSearchParams } from 'next/navigation'; import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'; -import { Clock, DotsThreeVertical, Envelope, Info, MapPinSimple, Pencil, Play, Plus, Trash } from '@phosphor-icons/react'; -import { useAuthenticatedData } from '../common/auth'; +import { CalendarCheck, CalendarDot, CalendarDots, Clock, ClockAfternoon, ClockCounterClockwise, DotsThreeVertical, Envelope, Info, Lightning, MapPinSimple, Pencil, Play, Plus, Trash } from '@phosphor-icons/react'; +import { useAuthenticatedData, UserProfile } from '../common/auth'; import LoginPrompt from '../components/loginPrompt/loginPrompt'; import { useToast } from '@/components/ui/use-toast'; import { ToastAction } from '@/components/ui/toast'; @@ -223,6 +223,7 @@ interface AutomationsCardProps { setNewAutomationData?: (data: AutomationsData) => void; isLoggedIn: boolean; setShowLoginPrompt: (showLoginPrompt: boolean) => void; + authenticatedData: UserProfile | null; } @@ -235,6 +236,33 @@ function AutomationsCard(props: AutomationsCardProps) { const automation = props.automation; + const [timeRecurrence, setTimeRecurrence] = useState(''); + + const [intervalString, setIntervalString] = useState(''); + + useEffect(() => { + // The updated automation data, if present, takes priority over the original automation data + const automationData = updatedAutomationData || automation; + setTimeRecurrence(getTimeRecurrenceFromCron(automationData.crontime)); + const frequency = getEveryBlahFromCron(automationData.crontime); + + console.log('frequency', frequency); + if (frequency === 'Day') { + setIntervalString('Daily'); + } else if (frequency === 'Week') { + const dayOfWeek = getDayOfWeekFromCron(automationData.crontime); + if (dayOfWeek === undefined) { + setIntervalString('Weekly'); + } else { + setIntervalString(`${weekDays[dayOfWeek]}`); + } + } else if (frequency === 'Month') { + const dayOfMonth = getDayOfMonthFromCron(automationData.crontime); + setIntervalString(`Monthly on the ${dayOfMonth}`); + } + }, [updatedAutomationData, props.automation]); + + useEffect(() => { const toastTitle = `Automation: ${updatedAutomationData?.subject || automation.subject}`; if (toastMessage) { @@ -254,117 +282,128 @@ function AutomationsCard(props: AutomationsCardProps) { } return ( -
- - - - {updatedAutomationData?.subject || automation.subject} - - - - - - - { - !props.suggestedCard && ( - { - setIsEditing(open); - }} - > - - - - - Edit Automation - - - - ) - } - { - !props.suggestedCard && ( - - ) - } - - - - - - {updatedAutomationData?.schedule || cronToHumanReadableString(automation.crontime)} - - - - {updatedAutomationData?.query_to_run || automation.query_to_run} - - - { - props.suggestedCard && props.setNewAutomationData && ( - { - setIsEditing(open); - }} - > - - + + + + { + !props.suggestedCard && ( + { + setIsEditing(open); + }} + > + + + + + Edit Automation + + + + ) + } + { + !props.suggestedCard && ( + - - - Add Automation - - - - ) - } - { - navigator.clipboard.writeText(createShareLink(automation)); - }} /> - - -
+ ) + } + { + navigator.clipboard.writeText(createShareLink(automation)); + }} /> + + + + + + {updatedAutomationData?.query_to_run || automation.query_to_run} + + +
+
+ +
+ {timeRecurrence} +
+
+
+ +
+ {intervalString} +
+
+
+ { + props.suggestedCard && props.setNewAutomationData && ( + { + setIsEditing(open); + }} + > + + + + + Add Automation + + + + ) + } +
+ ) } @@ -373,6 +412,7 @@ interface SharedAutomationCardProps { setNewAutomationData: (data: AutomationsData) => void; isLoggedIn: boolean; setShowLoginPrompt: (showLoginPrompt: boolean) => void; + authenticatedData: UserProfile | null; } function SharedAutomationCard(props: SharedAutomationCardProps) { @@ -407,8 +447,12 @@ function SharedAutomationCard(props: SharedAutomationCardProps) { - Create Automation + + + Create Automation + void; + authenticatedData: UserProfile | null; } function EditCard(props: EditCardProps) { @@ -524,7 +569,14 @@ function EditCard(props: EditCardProps) { } return ( - + ) } @@ -535,6 +587,8 @@ interface AutomationModificationFormProps { create?: boolean; isLoggedIn: boolean; setShowLoginPrompt: (showLoginPrompt: boolean) => void; + authenticatedData: UserProfile | null; + locationData: LocationData | null; } function AutomationModificationForm(props: AutomationModificationFormProps) { @@ -547,7 +601,7 @@ function AutomationModificationForm(props: AutomationModificationFormProps) { function recommendationPill(recommendationText: string, onChange: (value: any, event: React.MouseEvent) => void) { return ( + + + Create Automation + + + + ) + : ( + + ) + } + - { - authenticatedData ? ( - { - setIsCreating(open); - }} - > - - - - - Create Automation - - - - ) - : ( - - ) - } { ((!personalAutomations || personalAutomations.length === 0) && (allNewAutomations.length == 0)) && (
@@ -918,6 +1037,7 @@ export default function Automations() { Create Automation ( ( - void; buttonVariant?: keyof typeof buttonVariants; includeIcon?: boolean; + buttonClassName?: string; } function copyToClipboard(text: string) { @@ -36,7 +37,7 @@ export default function ShareLink(props: ShareLinkProps) { -