feat: dry run behaviour for connect atoms (#20699)
* add dry run prop for mocking actual behaviour without actual api calls * fix e2e tests * fixup * remove await present twice * fix: adjust success toast for apple connect dry run Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
This commit is contained in:
9 files changed
+88
-28
No files matched your search
@@ -26,6 +26,7 @@ export type OAuthConnectProps = {
|
||||
tooltipSide?: "top" | "bottom" | "left" | "right";
|
||||
isClickable?: boolean;
|
||||
onSuccess?: () => void;
|
||||
isDryRun?: boolean;
|
||||
};
|
||||
|
||||
export const OAuthConnect: FC<
|
||||
@@ -46,8 +47,9 @@ export const OAuthConnect: FC<
|
||||
tooltipSide = "bottom",
|
||||
isClickable,
|
||||
onSuccess,
|
||||
isDryRun,
|
||||
}) => {
|
||||
const { connect } = useConnect(calendar, redir);
|
||||
const { connect } = useConnect(calendar, redir, isDryRun);
|
||||
const { allowConnect, checked } = useCheck({
|
||||
onCheckError,
|
||||
calendar: calendar,
|
||||
|
||||
@@ -38,6 +38,7 @@ export const AppleConnect: FC<Partial<Omit<OAuthConnectProps, "redir">>> = ({
|
||||
tooltipSide = "bottom",
|
||||
isClickable,
|
||||
onSuccess,
|
||||
isDryRun = false,
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const form = useForm({
|
||||
@@ -134,7 +135,16 @@ export const AppleConnect: FC<Partial<Omit<OAuthConnectProps, "redir">>> = ({
|
||||
handleSubmit={async (values) => {
|
||||
const { username, password } = values;
|
||||
|
||||
await saveCredentials({ calendar: "apple", username, password });
|
||||
if (isDryRun) {
|
||||
form.reset();
|
||||
setIsDialogOpen(false);
|
||||
toast({
|
||||
description: "Calendar credentials added successfully",
|
||||
});
|
||||
onSuccess?.();
|
||||
} else {
|
||||
await saveCredentials({ calendar: "apple", username, password });
|
||||
}
|
||||
}}>
|
||||
<fieldset
|
||||
className="space-y-4"
|
||||
|
||||
@@ -20,6 +20,7 @@ export const GcalConnect: FC<Partial<OAuthConnectProps>> = ({
|
||||
tooltipSide,
|
||||
tooltip,
|
||||
isClickable,
|
||||
isDryRun,
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
@@ -36,6 +37,7 @@ export const GcalConnect: FC<Partial<OAuthConnectProps>> = ({
|
||||
tooltipSide={tooltipSide}
|
||||
tooltip={tooltip}
|
||||
isClickable={isClickable}
|
||||
isDryRun={isDryRun}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -20,6 +20,7 @@ export const OutlookConnect: FC<Partial<OAuthConnectProps>> = ({
|
||||
tooltipSide,
|
||||
tooltip,
|
||||
isClickable,
|
||||
isDryRun,
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
@@ -36,6 +37,7 @@ export const OutlookConnect: FC<Partial<OAuthConnectProps>> = ({
|
||||
tooltipSide={tooltipSide}
|
||||
tooltip={tooltip}
|
||||
isClickable={isClickable}
|
||||
isDryRun={isDryRun}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -13,7 +13,11 @@ interface IPUpdateOAuthCredentials {
|
||||
onError?: (err: ApiErrorResponse) => void;
|
||||
}
|
||||
|
||||
export const useGetRedirectUrl = (calendar: (typeof CALENDARS)[number], redir?: string) => {
|
||||
export const useGetRedirectUrl = (
|
||||
calendar: (typeof CALENDARS)[number],
|
||||
redir?: string,
|
||||
isDryRun?: boolean
|
||||
) => {
|
||||
const authUrl = useQuery({
|
||||
queryKey: getQueryKey(calendar),
|
||||
staleTime: Infinity,
|
||||
@@ -21,7 +25,7 @@ export const useGetRedirectUrl = (calendar: (typeof CALENDARS)[number], redir?:
|
||||
queryFn: () => {
|
||||
return http
|
||||
?.get<ApiResponse<{ authUrl: string }>>(
|
||||
`/calendars/${calendar}/connect${redir ? `?redir=${redir}` : ""}`
|
||||
`/calendars/${calendar}/connect?redir=${redir ?? ""}&isDryRun=${isDryRun ?? ""}`
|
||||
)
|
||||
.then(({ data: responseBody }) => {
|
||||
if (responseBody.status === SUCCESS_STATUS) {
|
||||
@@ -36,8 +40,8 @@ export const useGetRedirectUrl = (calendar: (typeof CALENDARS)[number], redir?:
|
||||
return authUrl;
|
||||
};
|
||||
|
||||
export const useConnect = (calendar: (typeof CALENDARS)[number], redir?: string) => {
|
||||
const { refetch } = useGetRedirectUrl(calendar, redir);
|
||||
export const useConnect = (calendar: (typeof CALENDARS)[number], redir?: string, isDryRun?: boolean) => {
|
||||
const { refetch } = useGetRedirectUrl(calendar, redir, isDryRun);
|
||||
|
||||
const connect = async () => {
|
||||
const redirectUri = await refetch();
|
||||
|
||||
Reference in new issue
Block a user