mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Show error message if update automation via web app fails
This commit is contained in:
@@ -269,6 +269,7 @@ interface AutomationsCardProps {
|
|||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
setShowLoginPrompt: (showLoginPrompt: boolean) => void;
|
setShowLoginPrompt: (showLoginPrompt: boolean) => void;
|
||||||
authenticatedData: UserProfile | null;
|
authenticatedData: UserProfile | null;
|
||||||
|
setToastMessage: (toastMessage: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AutomationsCard(props: AutomationsCardProps) {
|
function AutomationsCard(props: AutomationsCardProps) {
|
||||||
@@ -277,8 +278,6 @@ function AutomationsCard(props: AutomationsCardProps) {
|
|||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
const [isDeleted, setIsDeleted] = useState(false);
|
const [isDeleted, setIsDeleted] = useState(false);
|
||||||
const [toastMessage, setToastMessage] = useState("");
|
|
||||||
const { toast } = useToast();
|
|
||||||
|
|
||||||
const automation = props.automation;
|
const automation = props.automation;
|
||||||
|
|
||||||
@@ -306,18 +305,6 @@ function AutomationsCard(props: AutomationsCardProps) {
|
|||||||
}
|
}
|
||||||
}, [updatedAutomationData, automation]);
|
}, [updatedAutomationData, automation]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const toastTitle = `Automation: ${updatedAutomationData?.subject || automation.subject}`;
|
|
||||||
if (toastMessage) {
|
|
||||||
toast({
|
|
||||||
title: toastTitle,
|
|
||||||
description: toastMessage,
|
|
||||||
action: <ToastAction altText="Dismiss">Ok</ToastAction>,
|
|
||||||
});
|
|
||||||
setToastMessage("");
|
|
||||||
}
|
|
||||||
}, [toastMessage, updatedAutomationData, automation, toast]);
|
|
||||||
|
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -346,6 +333,7 @@ function AutomationsCard(props: AutomationsCardProps) {
|
|||||||
isCreating={isEditing}
|
isCreating={isEditing}
|
||||||
automation={updatedAutomationData || automation}
|
automation={updatedAutomationData || automation}
|
||||||
ipLocationData={props.locationData}
|
ipLocationData={props.locationData}
|
||||||
|
setToastMessage={props.setToastMessage}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<ShareLink
|
<ShareLink
|
||||||
@@ -365,7 +353,10 @@ function AutomationsCard(props: AutomationsCardProps) {
|
|||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
className="justify-start"
|
className="justify-start"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
sendAPreview(automation.id.toString(), setToastMessage);
|
sendAPreview(
|
||||||
|
automation.id.toString(),
|
||||||
|
props.setToastMessage,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Play className="h-4 w-4 mr-2" />
|
<Play className="h-4 w-4 mr-2" />
|
||||||
@@ -420,6 +411,7 @@ function AutomationsCard(props: AutomationsCardProps) {
|
|||||||
isCreating={isEditing}
|
isCreating={isEditing}
|
||||||
automation={automation}
|
automation={automation}
|
||||||
ipLocationData={props.locationData}
|
ipLocationData={props.locationData}
|
||||||
|
setToastMessage={props.setToastMessage}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
@@ -434,6 +426,7 @@ interface SharedAutomationCardProps {
|
|||||||
setShowLoginPrompt: (showLoginPrompt: boolean) => void;
|
setShowLoginPrompt: (showLoginPrompt: boolean) => void;
|
||||||
authenticatedData: UserProfile | null;
|
authenticatedData: UserProfile | null;
|
||||||
isMobileWidth: boolean;
|
isMobileWidth: boolean;
|
||||||
|
setToastMessage: (toastMessage: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SharedAutomationCard(props: SharedAutomationCardProps) {
|
function SharedAutomationCard(props: SharedAutomationCardProps) {
|
||||||
@@ -470,6 +463,7 @@ function SharedAutomationCard(props: SharedAutomationCardProps) {
|
|||||||
isCreating={isCreating}
|
isCreating={isCreating}
|
||||||
automation={automation}
|
automation={automation}
|
||||||
ipLocationData={props.locationData}
|
ipLocationData={props.locationData}
|
||||||
|
setToastMessage={props.setToastMessage}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
}
|
}
|
||||||
@@ -492,6 +486,7 @@ interface EditCardProps {
|
|||||||
isLoggedIn: boolean;
|
isLoggedIn: boolean;
|
||||||
setShowLoginPrompt: (showLoginPrompt: boolean) => void;
|
setShowLoginPrompt: (showLoginPrompt: boolean) => void;
|
||||||
authenticatedData: UserProfile | null;
|
authenticatedData: UserProfile | null;
|
||||||
|
setToastMessage: (toastMessage: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function EditCard(props: EditCardProps) {
|
function EditCard(props: EditCardProps) {
|
||||||
@@ -552,6 +547,15 @@ function EditCard(props: EditCardProps) {
|
|||||||
crontime: data.crontime,
|
crontime: data.crontime,
|
||||||
next: data.next,
|
next: data.next,
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error saving automation:", error);
|
||||||
|
// Reset saving state
|
||||||
|
props.setIsEditing(false);
|
||||||
|
// Show error message
|
||||||
|
props.setToastMessage(
|
||||||
|
"Sorry, something went wrong. Try again or contact team@khoj.dev.",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -919,6 +923,7 @@ interface AutomationComponentWrapperProps {
|
|||||||
isCreating: boolean;
|
isCreating: boolean;
|
||||||
ipLocationData: LocationData | null | undefined;
|
ipLocationData: LocationData | null | undefined;
|
||||||
automation?: AutomationsData;
|
automation?: AutomationsData;
|
||||||
|
setToastMessage: (toastMessage: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AutomationComponentWrapper(props: AutomationComponentWrapperProps) {
|
function AutomationComponentWrapper(props: AutomationComponentWrapperProps) {
|
||||||
@@ -946,6 +951,7 @@ function AutomationComponentWrapper(props: AutomationComponentWrapperProps) {
|
|||||||
setShowLoginPrompt={props.setShowLoginPrompt}
|
setShowLoginPrompt={props.setShowLoginPrompt}
|
||||||
setUpdatedAutomationData={props.setNewAutomationData}
|
setUpdatedAutomationData={props.setNewAutomationData}
|
||||||
locationData={props.ipLocationData}
|
locationData={props.ipLocationData}
|
||||||
|
setToastMessage={props.setToastMessage}
|
||||||
/>
|
/>
|
||||||
</DrawerContent>
|
</DrawerContent>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
@@ -973,6 +979,7 @@ function AutomationComponentWrapper(props: AutomationComponentWrapperProps) {
|
|||||||
setShowLoginPrompt={props.setShowLoginPrompt}
|
setShowLoginPrompt={props.setShowLoginPrompt}
|
||||||
setUpdatedAutomationData={props.setNewAutomationData}
|
setUpdatedAutomationData={props.setNewAutomationData}
|
||||||
locationData={props.ipLocationData}
|
locationData={props.ipLocationData}
|
||||||
|
setToastMessage={props.setToastMessage}
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
@@ -1000,6 +1007,8 @@ export default function Automations() {
|
|||||||
const [showLoginPrompt, setShowLoginPrompt] = useState(false);
|
const [showLoginPrompt, setShowLoginPrompt] = useState(false);
|
||||||
const isMobileWidth = useIsMobileWidth();
|
const isMobileWidth = useIsMobileWidth();
|
||||||
const { locationData, locationDataError, locationDataLoading } = useIPLocationData();
|
const { locationData, locationDataError, locationDataLoading } = useIPLocationData();
|
||||||
|
const [toastMessage, setToastMessage] = useState("");
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (newAutomationData) {
|
if (newAutomationData) {
|
||||||
@@ -1026,6 +1035,19 @@ export default function Automations() {
|
|||||||
}
|
}
|
||||||
}, [personalAutomations, allNewAutomations]);
|
}, [personalAutomations, allNewAutomations]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const toastTitle = `Automation`;
|
||||||
|
if (toastMessage) {
|
||||||
|
toast({
|
||||||
|
title: toastTitle,
|
||||||
|
description: toastMessage,
|
||||||
|
action: <ToastAction altText="Dismiss">Ok</ToastAction>,
|
||||||
|
variant: toastMessage.includes("Sorry") ? "destructive" : "default",
|
||||||
|
});
|
||||||
|
setToastMessage("");
|
||||||
|
}
|
||||||
|
}, [toastMessage]);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return <InlineLoading message="Oops, something went wrong. Please refresh the page." />;
|
return <InlineLoading message="Oops, something went wrong. Please refresh the page." />;
|
||||||
|
|
||||||
@@ -1100,6 +1122,7 @@ export default function Automations() {
|
|||||||
authenticatedData={authenticatedData}
|
authenticatedData={authenticatedData}
|
||||||
isCreating={isCreating}
|
isCreating={isCreating}
|
||||||
ipLocationData={locationData}
|
ipLocationData={locationData}
|
||||||
|
setToastMessage={setToastMessage}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
@@ -1120,6 +1143,7 @@ export default function Automations() {
|
|||||||
isLoggedIn={authenticatedData ? true : false}
|
isLoggedIn={authenticatedData ? true : false}
|
||||||
setShowLoginPrompt={setShowLoginPrompt}
|
setShowLoginPrompt={setShowLoginPrompt}
|
||||||
setNewAutomationData={setNewAutomationData}
|
setNewAutomationData={setNewAutomationData}
|
||||||
|
setToastMessage={setToastMessage}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
{isLoading && <InlineLoading message="booting up your automations" />}
|
{isLoading && <InlineLoading message="booting up your automations" />}
|
||||||
@@ -1135,6 +1159,7 @@ export default function Automations() {
|
|||||||
locationData={locationData}
|
locationData={locationData}
|
||||||
isLoggedIn={authenticatedData ? true : false}
|
isLoggedIn={authenticatedData ? true : false}
|
||||||
setShowLoginPrompt={setShowLoginPrompt}
|
setShowLoginPrompt={setShowLoginPrompt}
|
||||||
|
setToastMessage={setToastMessage}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{authenticatedData &&
|
{authenticatedData &&
|
||||||
@@ -1147,6 +1172,7 @@ export default function Automations() {
|
|||||||
locationData={locationData}
|
locationData={locationData}
|
||||||
isLoggedIn={authenticatedData ? true : false}
|
isLoggedIn={authenticatedData ? true : false}
|
||||||
setShowLoginPrompt={setShowLoginPrompt}
|
setShowLoginPrompt={setShowLoginPrompt}
|
||||||
|
setToastMessage={setToastMessage}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -1163,6 +1189,7 @@ export default function Automations() {
|
|||||||
isLoggedIn={authenticatedData ? true : false}
|
isLoggedIn={authenticatedData ? true : false}
|
||||||
setShowLoginPrompt={setShowLoginPrompt}
|
setShowLoginPrompt={setShowLoginPrompt}
|
||||||
suggestedCard={true}
|
suggestedCard={true}
|
||||||
|
setToastMessage={setToastMessage}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user