Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
addSharedCalendar,
|
addSharedCalendar,
|
||||||
|
exportCalendar,
|
||||||
getCalendar,
|
getCalendar,
|
||||||
getCalendars,
|
getCalendars,
|
||||||
getSecretLink,
|
getSecretLink,
|
||||||
@@ -149,6 +150,20 @@ describe("Calendar API", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("get export data ", async () => {
|
||||||
|
const calLink = "/calendars/calId.json";
|
||||||
|
(api.get as jest.Mock).mockReturnValue({
|
||||||
|
text: jest.fn().mockResolvedValue("data"),
|
||||||
|
});
|
||||||
|
const data = await exportCalendar(calLink);
|
||||||
|
|
||||||
|
expect(api.get).toHaveBeenCalledWith(`dav${calLink}?export`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/calendar",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("When adding a sharedCal with #default as a name a new name is sent to the back", async () => {
|
it("When adding a sharedCal with #default as a name a new name is sent to the back", async () => {
|
||||||
const mockApiPost = jest.spyOn(api, "post");
|
const mockApiPost = jest.spyOn(api, "post");
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
||||||
|
import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
IconButton,
|
IconButton,
|
||||||
@@ -6,13 +7,19 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Typography,
|
Typography,
|
||||||
InputAdornment,
|
InputAdornment,
|
||||||
|
Backdrop,
|
||||||
|
CircularProgress,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { getSecretLink } from "../../features/Calendars/CalendarApi";
|
import {
|
||||||
|
exportCalendar,
|
||||||
|
getSecretLink,
|
||||||
|
} from "../../features/Calendars/CalendarApi";
|
||||||
import { Calendars } from "../../features/Calendars/CalendarTypes";
|
import { Calendars } from "../../features/Calendars/CalendarTypes";
|
||||||
import { FieldWithLabel } from "../Event/components/FieldWithLabel";
|
import { FieldWithLabel } from "../Event/components/FieldWithLabel";
|
||||||
import { SnackbarAlert } from "../Loading/SnackBarAlert";
|
import { SnackbarAlert } from "../Loading/SnackBarAlert";
|
||||||
import { useI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
import { useI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
||||||
|
import { ErrorSnackbar } from "../Error/ErrorSnackbar";
|
||||||
|
|
||||||
export function AccessTab({ calendar }: { calendar: Calendars }) {
|
export function AccessTab({ calendar }: { calendar: Calendars }) {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
@@ -45,6 +52,35 @@ export function AccessTab({ calendar }: { calendar: Calendars }) {
|
|||||||
setSecretLink(newSecret.secretLink);
|
setSecretLink(newSecret.secretLink);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [exportLoading, setExportLoading] = useState(false);
|
||||||
|
const [exportError, setExportError] = useState("");
|
||||||
|
|
||||||
|
const handleExport = async () => {
|
||||||
|
try {
|
||||||
|
setExportLoading(true);
|
||||||
|
const exportedData = await exportCalendar(
|
||||||
|
calendar.link.replace(".json", "")
|
||||||
|
);
|
||||||
|
const blob = new Blob([exportedData], {
|
||||||
|
type: "text/calendar",
|
||||||
|
});
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.download = `${calendar.id.split("/")[1]}.ics`;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
} catch (e) {
|
||||||
|
setExportError((e as Error).message);
|
||||||
|
setExportLoading(false);
|
||||||
|
} finally {
|
||||||
|
setExportLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FieldWithLabel label={t("calendar.caldav_access")} isExpanded={false}>
|
<FieldWithLabel label={t("calendar.caldav_access")} isExpanded={false}>
|
||||||
@@ -84,24 +120,49 @@ export function AccessTab({ calendar }: { calendar: Calendars }) {
|
|||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button variant="outlined" onClick={handleResetSecretLink}>
|
<Button variant="contained" onClick={handleResetSecretLink}>
|
||||||
{t("actions.reset")}
|
{t("actions.reset")}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
sx={{ color: "text.secondary", mt: 1, lineHeight: 1.5 }}
|
||||||
|
>
|
||||||
|
{t("calendar.secretUrlDesc")}
|
||||||
|
</Typography>
|
||||||
</FieldWithLabel>
|
</FieldWithLabel>
|
||||||
|
|
||||||
<Typography
|
<FieldWithLabel label={t("calendar.exportCalendar")} isExpanded={false}>
|
||||||
variant="body2"
|
<Typography
|
||||||
sx={{ color: "text.secondary", mt: 1, lineHeight: 1.5 }}
|
variant="body2"
|
||||||
>
|
sx={{ color: "text.secondary", m: 1, lineHeight: 1.5 }}
|
||||||
{t("calendar.secretUrlDesc")}
|
>
|
||||||
</Typography>
|
{t("calendar.exportDesc")}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={handleExport}
|
||||||
|
startIcon={!exportLoading && <FileDownloadOutlinedIcon />}
|
||||||
|
disabled={exportLoading}
|
||||||
|
>
|
||||||
|
{exportLoading ? (
|
||||||
|
<Box display="flex" alignItems="center" gap={1}>
|
||||||
|
<CircularProgress size={18} />
|
||||||
|
{t("actions.exporting")}
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
t("actions.export")
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</FieldWithLabel>
|
||||||
|
|
||||||
<SnackbarAlert
|
<SnackbarAlert
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
open={open}
|
open={open}
|
||||||
message={t("common.link_copied")}
|
message={t("common.link_copied")}
|
||||||
/>
|
/>
|
||||||
|
<ErrorSnackbar error={exportError} type="calendar" />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,3 +139,14 @@ export async function getSecretLink(calLink: string, reset: boolean) {
|
|||||||
.json();
|
.json();
|
||||||
return response as { secretLink: string };
|
return response as { secretLink: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function exportCalendar(calLink: string) {
|
||||||
|
const response = await api
|
||||||
|
.get(`dav${calLink}?export`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/calendar",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.text();
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|||||||
+5
-1
@@ -7,6 +7,8 @@
|
|||||||
"caldav_access": "CalDAV access",
|
"caldav_access": "CalDAV access",
|
||||||
"secretUrl": "Secret URL",
|
"secretUrl": "Secret URL",
|
||||||
"secretUrlDesc": "The secret address can be used to view all calendar events even without access permissions. You can reset your current secret address and get a new one.",
|
"secretUrlDesc": "The secret address can be used to view all calendar events even without access permissions. You can reset your current secret address and get a new one.",
|
||||||
|
"exportCalendar": "Export calendar",
|
||||||
|
"exportDesc": "Export your calendar to iCalendar format file (.ics) which you can import to other applications.",
|
||||||
"import_file_description": "Import events from an ICS file to one of your calendars.",
|
"import_file_description": "Import events from an ICS file to one of your calendars.",
|
||||||
"ics_feed_url": "ICS feed URL",
|
"ics_feed_url": "ICS feed URL",
|
||||||
"import_to": "Import to",
|
"import_to": "Import to",
|
||||||
@@ -31,7 +33,9 @@
|
|||||||
"create": "Create",
|
"create": "Create",
|
||||||
"import": "Import",
|
"import": "Import",
|
||||||
"add": "Add",
|
"add": "Add",
|
||||||
"reset": "Reset"
|
"reset": "Reset",
|
||||||
|
"export": "Export",
|
||||||
|
"exporting": "Exporting..."
|
||||||
},
|
},
|
||||||
"common": {
|
"common": {
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
|
|||||||
+5
-1
@@ -7,6 +7,8 @@
|
|||||||
"caldav_access": "Accès CalDAV",
|
"caldav_access": "Accès CalDAV",
|
||||||
"secretUrl": "URL secrète",
|
"secretUrl": "URL secrète",
|
||||||
"secretUrlDesc": "L'adresse secrète peut être utilisée pour visualiser tous vos calendiers même sans permissions. Vous pouvez la réinitialiser pour en obtenir une nouvelle.",
|
"secretUrlDesc": "L'adresse secrète peut être utilisée pour visualiser tous vos calendiers même sans permissions. Vous pouvez la réinitialiser pour en obtenir une nouvelle.",
|
||||||
|
"exportCalendar": "Exporter le calendrier",
|
||||||
|
"exportDesc": "Exportez votre calendrier au format iCalendar (.ics) que vous pouvez utiliser pour l'importer dans d'autres applications.",
|
||||||
"import_file_description": "Importer des événements depuis un fichier ICS vers l'un de vos calendriers.",
|
"import_file_description": "Importer des événements depuis un fichier ICS vers l'un de vos calendriers.",
|
||||||
"ics_feed_url": "URL du flux ICS",
|
"ics_feed_url": "URL du flux ICS",
|
||||||
"import_to": "Importer vers",
|
"import_to": "Importer vers",
|
||||||
@@ -31,7 +33,9 @@
|
|||||||
"create": "Créer",
|
"create": "Créer",
|
||||||
"import": "Importer",
|
"import": "Importer",
|
||||||
"add": "Ajouter",
|
"add": "Ajouter",
|
||||||
"reset": "Réinitialiser"
|
"reset": "Réinitialiser",
|
||||||
|
"export": "Exporter",
|
||||||
|
"exporting": "En cours d'exportation..."
|
||||||
},
|
},
|
||||||
"common": {
|
"common": {
|
||||||
"cancel": "Annuler",
|
"cancel": "Annuler",
|
||||||
|
|||||||
Reference in New Issue
Block a user