Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web][photos] Refresh family storage limit dialog

AswinAsok7f33c6d16891
diff --git a/web/apps/photos/public/images/storage-limit/close.svg b/web/apps/photos/public/images/storage-limit/close.svg
new file mode 100644
index 0000000000..784fa6713e
--- /dev/null
+++ b/web/apps/photos/public/images/storage-limit/close.svg
@@ -0,0 +1,5 @@
+<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="elements">
+<path id="Vector" d="M11.25 0.75L6 6M6 6L0.75 11.25M6 6L0.75 0.75M6 6L11.25 11.25" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke="black" style="stroke:black;stroke-opacity:1;"/>
+</g>
+</svg>
diff --git a/web/apps/photos/public/images/storage-limit/selected.svg b/web/apps/photos/public/images/storage-limit/selected.svg
new file mode 100644
index 0000000000..c94116fcce
--- /dev/null
+++ b/web/apps/photos/public/images/storage-limit/selected.svg
@@ -0,0 +1,13 @@
+<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Radio Button">
+<g clip-path="url(#clip0_0_137)">
+<path id="Container" d="M8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0ZM8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1Z" fill="#08C225" style="fill:#08C225;fill:color(display-p3 0.0314 0.7608 0.1451);fill-opacity:1;"/>
+<circle id="On" cx="8" cy="8" r="4" fill="#08C225" style="fill:#08C225;fill:color(display-p3 0.0314 0.7608 0.1451);fill-opacity:1;"/>
+</g>
+</g>
+<defs>
+<clipPath id="clip0_0_137">
+<path d="M0 5C0 2.23858 2.23858 0 5 0H11C13.7614 0 16 2.23858 16 5V11C16 13.7614 13.7614 16 11 16H5C2.23858 16 0 13.7614 0 11V5Z" fill="white" style="fill:white;fill-opacity:1;"/>
+</clipPath>
+</defs>
+</svg>
diff --git a/web/apps/photos/public/images/storage-limit/unselected.svg b/web/apps/photos/public/images/storage-limit/unselected.svg
new file mode 100644
index 0000000000..f5abaf679d
--- /dev/null
+++ b/web/apps/photos/public/images/storage-limit/unselected.svg
@@ -0,0 +1,12 @@
+<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+<g id="Radio Button">
+<g clip-path="url(#clip0_0_128)">
+<path id="Container" d="M8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0ZM8 1C4.13401 1 1 4.13401 1 8C1 11.866 4.13401 15 8 15C11.866 15 15 11.866 15 8C15 4.13401 11.866 1 8 1Z" fill="#969696" style="fill:#969696;fill:color(display-p3 0.5882 0.5882 0.5882);fill-opacity:1;"/>
+</g>
+</g>
+<defs>
+<clipPath id="clip0_0_128">
+<path d="M0 5C0 2.23858 2.23858 0 5 0H11C13.7614 0 16 2.23858 16 5V11C16 13.7614 13.7614 16 11 16H5C2.23858 16 0 13.7614 0 11V5Z" fill="white" style="fill:white;fill-opacity:1;"/>
+</clipPath>
+</defs>
+</svg>
diff --git a/web/apps/photos/src/components/FamilyManagement.tsx b/web/apps/photos/src/components/FamilyManagement.tsx
index 0127dda666..281fef23f7 100644
--- a/web/apps/photos/src/components/FamilyManagement.tsx
+++ b/web/apps/photos/src/components/FamilyManagement.tsx
@@ -17,8 +17,11 @@ import {
DialogContent,
DialogTitle,
Divider,
+ FormControlLabel,
IconButton,
InputBase,
+ Radio,
+ RadioGroup,
Stack,
TextField,
Typography,
@@ -215,6 +218,11 @@ export const FamilyManagement: React.FC<FamilyManagementProps> = ({
/>
<StorageLimitDialog
member={editingMember}
+ color={avatarBackgroundColor(
+ members.findIndex(
+ (member) => member.id == editingMember?.id,
+ ),
+ )}
totalStorage={
(userDetails?.familyData?.storage ?? 0) +
(userDetails?.storageBonus ?? 0)
@@ -638,31 +646,32 @@ const inviteErrorKey = (error: unknown) => {
const StorageLimitDialog: React.FC<{
member?: FamilyMember;
+ color: string;
totalStorage: number;
onClose: () => void;
-}> = ({ member, totalStorage, onClose }) => {
+}> = ({ member, color, totalStorage, onClose }) => {
const { onGenericError } = useBaseContext();
const [value, setValue] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
+ const [limited, setLimited] = useState(false);
useEffect(() => {
- setValue(
- member?.storageLimit == undefined
- ? ""
- : String(member.storageLimit / 1024 ** 3),
- );
+ setLimited(member?.storageLimit != undefined);
+ setValue(String((member?.storageLimit ?? totalStorage) / 1024 ** 3));
setError("");
- }, [member]);
+ }, [member, totalStorage]);
const save = async () => {
- const storageLimit = value
+ if (loading || !member) return;
+ const storageLimit = limited
? Math.round(Number(value) * 1024 ** 3)
: null;
if (
storageLimit != null &&
- (!Number.isFinite(storageLimit) ||
- storageLimit < (member?.usage ?? 0) ||
+ (!value.trim() ||
+ !Number.isFinite(storageLimit) ||
+ storageLimit < (member.usage ?? 0) ||
storageLimit > totalStorage)
) {
setError(t("family_storage_limit_invalid"));
@@ -670,7 +679,7 @@ const StorageLimitDialog: React.FC<{
}
setLoading(true);
try {
- await modifyFamilyMemberStorage(member!.id, storageLimit);
+ await modifyFamilyMemberStorage(member.id, storageLimit);
onClose();
} catch (e) {
if (isHTTPErrorWithStatus(e, 426))
@@ -682,41 +691,325 @@ const StorageLimitDialog: React.FC<{
};
return (
- <Dialog open={!!member} {...{ onClose }} maxWidth="xs" fullWidth>
- <Stack direction="row" sx={{ p: "20px 16px 8px 24px" }}>
- <Typography variant="h3" sx={{ flex: 1 }}>
- {t("set_storage_limit")}
- </Typography>
- <DialogCloseIconButton {...{ onClose }} />
+ <Dialog
+ open={!!member}
+ onClose={loading ? undefined : onClose}
+ aria-labelledby="storage-limit-title"
+ maxWidth="xs"
+ fullWidth
+ slotProps={{
+ paper: {
+ sx: {
+ width: 420,
+ maxWidth: "calc(100% - 32px)",
+ m: 2,
+ p: "20px",
+ gap: 2,
+ borderRadius: "20px",
+ border: "1px solid",
+ borderColor: "stroke.faint",
+ backgroundImage:
+ "linear-gradient(var(--mui-palette-fill-faint), var(--mui-palette-fill-faint))",
+ },
+ },
+ }}
+ >
+ <Stack direction="row" sx={{ alignItems: "center", gap: 1 }}>
+ <DialogTitle
+ id="storage-limit-title"
+ sx={{
+ "&&": { p: 0 },
+ flex: 1,
+ fontSize: 20,
+ lineHeight: "28px",
+ fontWeight: 600,
+ }}
+ >
+ {t("storage_limit")}
+ </DialogTitle>
+ <IconButton
+ aria-label={t("close")}
+ onClick={onClose}
+ disabled={loading}
+ sx={{ width: 38, height: 38, bgcolor: "background.paper" }}
+ >
+ <Box
+ component="img"
+ alt=""
+ src="/images/storage-limit/close.svg"
+ sx={(theme) => ({
+ ...theme.applyStyles("dark", {
+ filter: "invert(1)",
+ }),
+ })}
+ />
+ </IconButton>
</Stack>
- <DialogContent>
- <Stack sx={{ gap: 2 }}>
- <TextField
- autoFocus
- type="number"
- label={t("storage_limit_gb")}
- value={value}
- error={!!error}
- helperText={error || t("storage_limit_hint")}
- slotProps={{ htmlInput: { min: 0, step: "any" } }}
- onChange={(e) => {
- setValue(e.target.value);
- setError("");
+ <Stack
+ component="form"
+ onSubmit={(event) => {
+ event.preventDefault();
+ void save();
+ }}
+ noValidate
+ sx={{ gap: 2 }}
+ >
+ <Stack
+ direction="row"
+ sx={{
+ alignItems: "center",
+ gap: 1.5,
+ p: 1.5,
+ minHeight: 60,
+ borderRadius: "20px",
+ bgcolor: "background.paper",
+ }}
+ >
+ <Box
+ sx={{
+ width: 36,
+ display: "flex",
+ justifyContent: "center",
+ flexShrink: 0,
}}
- onKeyDown={(e) => {
- if (e.key == "Enter") void save();
+ >
+ <Avatar
+ sx={{
+ width: 24,
+ height: 24,
+ bgcolor: color,
+ color: avatarTextColor,
+ fontSize: 12,
+ fontWeight: 500,
+ }}
+ >
+ {member?.email[0]?.toUpperCase()}
+ </Avatar>
+ </Box>
+ <Stack sx={{ minWidth: 0, gap: 0.5 }}>
+ <Typography
+ variant="small"
+ noWrap
+ sx={{
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ }}
+ >
+ {member?.email}
+ </Typography>
+ <Typography
+ variant="mini"
+ sx={{
+ color: "text.muted",
+ fontWeight: 500,
+ lineHeight: "16px",
+ }}
+ >
+ {t("family_member_using_storage", {
+ usage: formattedStorageByteSize(
+ member?.usage ?? 0,
+ ),
+ })}
+ </Typography>
+ </Stack>
+ </Stack>
+ <RadioGroup
+ aria-labelledby="storage-limit-title"
+ name="storage-limit"
+ value={limited ? "limited" : "unlimited"}
+ onChange={(_, value) => {
+ setLimited(value == "limited");
+ setError("");
+ }}
+ sx={{
+ gap: 1.5,
+ "& .MuiFormControlLabel-root": { m: 0, gap: 1.5 },
+ "& .MuiFormControlLabel-label": {
+ fontSize: 14,
+ lineHeight: "20px",
+ fontWeight: 500,
+ },
+ "& .MuiRadio-root": {
+ p: 0,
+ "&.Mui-focusVisible": {
+ outline: "2px solid",
+ outlineColor: "accent.main",
+ outlineOffset: 3,
+ },
+ },
+ }}
+ >
+ <FormControlLabel
+ value="unlimited"
+ disabled={loading}
+ control={
+ <Radio
+ icon={
+ <img
+ alt=""
+ src="/images/storage-limit/unselected.svg"
+ />
+ }
+ checkedIcon={
+ <img
+ alt=""
+ src="/images/storage-limit/selected.svg"
+ />
+ }
+ />
+ }
+ label={t("no_limit")}
+ sx={{
+ p: "14px",
+ borderRadius: "20px",
+ bgcolor: "background.paper",
}}
/>
+ <Stack
+ direction="row"
+ onClick={() => {
+ if (!loading) {
+ setLimited(true);
+ setError("");
+ }
+ }}
+ sx={{
+ alignItems: "center",
+ gap: 1.5,
+ px: "14px",
+ py: "6px",
+ borderRadius: "20px",
+ bgcolor: "background.paper",
+ }}
+ >
+ <FormControlLabel
+ value="limited"
+ disabled={loading}
+ control={
+ <Radio
+ icon={
+ <img
+ alt=""
+ src="/images/storage-limit/unselected.svg"
+ />
+ }
+ checkedIcon={
+ <img
+ alt=""
+ src="/images/storage-limit/selected.svg"
+ />
+ }
+ />
+ }
+ label={t("storage_limit_up_to")}
+ />
+ <TextField
+ variant="outlined"
+ type="number"
+ value={value}
+ disabled={loading}
+ error={!!error}
+ onFocus={() => setLimited(true)}
+ slotProps={{
+ htmlInput: {
+ "aria-label": t("storage_limit_gb"),
+ "aria-describedby": error
+ ? "storage-limit-error"
+ : undefined,
+ min: (member?.usage ?? 0) / 1024 ** 3,
+ max: totalStorage / 1024 ** 3,
+ step: "any",
+ },
+ }}
+ onChange={(e) => {
+ setValue(e.target.value);
+ setError("");
+ }}
+ sx={{
+ m: 0,
+ width: 100,
+ minWidth: 0,
+ "& .MuiInputBase-root": {
+ height: 36,
+ bgcolor: "fill.faint",
+ borderRadius: "12px",
+ },
+ "& .MuiOutlinedInput-notchedOutline": {
+ borderColor: "stroke.muted",
+ },
+ "& .MuiInputBase-input": {
+ p: "8px 12px",
+ fontSize: 14,
+ fontWeight: 500,
+ },
+ "& input::-webkit-inner-spin-button, & input::-webkit-outer-spin-button":
+ { WebkitAppearance: "none", m: 0 },
+ "& input": { MozAppearance: "textfield" },
+ }}
+ />
+ <Typography
+ variant="small"
+ sx={{
+ color: "text.muted",
+ fontSize: 14,
+ fontWeight: 500,
+ }}
+ >
+ GB
+ </Typography>
+ </Stack>
+ </RadioGroup>
+ {!!error && (
+ <Typography
+ id="storage-limit-error"
+ role="alert"
+ variant="mini"
+ sx={{ color: "critical.main" }}
+ >
+ {error}
+ </Typography>
+ )}
+ <Typography
+ variant="mini"
+ sx={{ color: "text.muted", lineHeight: "17px" }}
+ >
+ {t("storage_limit_explanation")}
+ </Typography>
+ <Stack
+ sx={{
+ gap: 1.5,
+ "& .MuiButton-root": {
+ height: 52,
+ px: 3,
+ borderRadius: "20px",
+ fontSize: 14,
+ lineHeight: "20px",
+ },
+ }}
+ >
<LoadingButton
fullWidth
+ type="submit"
color="accent"
loading={loading}
- onClick={() => void save()}
>
{t("save")}
</LoadingButton>
+ <FocusVisibleButton
+ fullWidth
+ color="secondary"
+ disabled={loading}
+ onClick={onClose}
+ sx={{
+ bgcolor: "secondary.dark",
+ "&:hover": { bgcolor: "fill.muted" },
+ }}
+ >
+ {t("cancel")}
+ </FocusVisibleButton>
</Stack>
- </DialogContent>
+ </Stack>
</Dialog>
);
};
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index 8959541143..649f46de81 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -404,6 +404,11 @@
"remove_family_member": "Remove family member",
"remove_family_member_confirm": "Remove {{email}} from your family?",
"set_storage_limit": "Set storage limit",
+ "storage_limit": "Storage limit",
+ "no_limit": "No limit",
+ "storage_limit_up_to": "Up to",
+ "family_member_using_storage": "Using {{usage}}",
+ "storage_limit_explanation": "Limits only pause new backups. Nothing already backed up is removed.",
"storage_limit_gb": "Storage limit (GB)",
"storage_limit_hint": "Leave blank for no limit.",
"family_storage_limit_invalid": "The limit must be between the member's current usage and the family's total storage.",