2022-08-03 18:02:44 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { getPermissionDescription } from '../../../../helpers/utils/permission';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import { formatDate } from '../../../../helpers/utils/util';
|
|
|
|
import Typography from '../../../ui/typography/typography';
|
2023-02-02 21:15:26 +01:00
|
|
|
import { TextColor } from '../../../../helpers/constants/design-system';
|
2022-08-03 18:02:44 +02:00
|
|
|
|
|
|
|
export default function UpdateSnapPermissionList({
|
|
|
|
approvedPermissions,
|
|
|
|
revokedPermissions,
|
|
|
|
newPermissions,
|
|
|
|
}) {
|
|
|
|
const t = useI18nContext();
|
|
|
|
|
|
|
|
const ApprovedPermissions = () => {
|
2022-11-14 11:50:17 +01:00
|
|
|
return Object.entries(approvedPermissions).map(
|
|
|
|
([permissionName, permissionValue]) => {
|
2022-12-01 14:38:56 +01:00
|
|
|
const permissions = getPermissionDescription(
|
2022-11-14 11:50:17 +01:00
|
|
|
t,
|
|
|
|
permissionName,
|
|
|
|
permissionValue,
|
|
|
|
);
|
|
|
|
const { date } = permissionValue;
|
|
|
|
const formattedDate = formatDate(date, 'yyyy-MM-dd');
|
2022-12-01 14:38:56 +01:00
|
|
|
return permissions.map(({ label, rightIcon }) => (
|
2022-11-14 11:50:17 +01:00
|
|
|
<div className="approved-permission" key={permissionName}>
|
|
|
|
<i className="fas fa-check" />
|
|
|
|
<div className="permission-description">
|
|
|
|
{label}
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-11-14 11:50:17 +01:00
|
|
|
className="permission-description-subtext"
|
|
|
|
boxProps={{ paddingTop: 1 }}
|
|
|
|
>
|
|
|
|
{t('approvedOn', [formattedDate])}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
{rightIcon && <i className={rightIcon} />}
|
2022-08-03 18:02:44 +02:00
|
|
|
</div>
|
2022-12-01 14:38:56 +01:00
|
|
|
));
|
2022-11-14 11:50:17 +01:00
|
|
|
},
|
|
|
|
);
|
2022-08-03 18:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const RevokedPermissions = () => {
|
2022-11-14 11:50:17 +01:00
|
|
|
return Object.entries(revokedPermissions).map(
|
|
|
|
([permissionName, permissionValue]) => {
|
2022-12-01 14:38:56 +01:00
|
|
|
const permissions = getPermissionDescription(
|
2022-11-14 11:50:17 +01:00
|
|
|
t,
|
|
|
|
permissionName,
|
|
|
|
permissionValue,
|
|
|
|
);
|
2022-12-01 14:38:56 +01:00
|
|
|
return permissions.map(({ label, rightIcon }) => (
|
2022-11-14 11:50:17 +01:00
|
|
|
<div className="revoked-permission" key={permissionName}>
|
|
|
|
<i className="fas fa-x" />
|
|
|
|
<div className="permission-description">
|
|
|
|
{label}
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-11-14 11:50:17 +01:00
|
|
|
boxProps={{ paddingTop: 1 }}
|
|
|
|
className="permission-description-subtext"
|
|
|
|
>
|
|
|
|
{t('permissionRevoked')}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
{rightIcon && <i className={rightIcon} />}
|
2022-08-03 18:02:44 +02:00
|
|
|
</div>
|
2022-12-01 14:38:56 +01:00
|
|
|
));
|
2022-11-14 11:50:17 +01:00
|
|
|
},
|
|
|
|
);
|
2022-08-03 18:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const NewPermissions = () => {
|
2022-11-14 11:50:17 +01:00
|
|
|
return Object.entries(newPermissions).map(
|
|
|
|
([permissionName, permissionValue]) => {
|
2022-12-01 14:38:56 +01:00
|
|
|
const permissions = getPermissionDescription(
|
2022-11-14 11:50:17 +01:00
|
|
|
t,
|
|
|
|
permissionName,
|
|
|
|
permissionValue,
|
|
|
|
);
|
2022-12-01 14:38:56 +01:00
|
|
|
return permissions.map(({ label, rightIcon }) => (
|
2022-11-14 11:50:17 +01:00
|
|
|
<div className="new-permission" key={permissionName}>
|
|
|
|
<i className="fas fa-arrow-right" />
|
|
|
|
<div className="permission-description">
|
|
|
|
{label}
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
2022-11-14 11:50:17 +01:00
|
|
|
boxProps={{ paddingTop: 1 }}
|
|
|
|
className="permission-description-subtext"
|
|
|
|
>
|
|
|
|
{t('permissionRequested')}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
{rightIcon && <i className={rightIcon} />}
|
2022-08-03 18:02:44 +02:00
|
|
|
</div>
|
2022-12-01 14:38:56 +01:00
|
|
|
));
|
2022-11-14 11:50:17 +01:00
|
|
|
},
|
|
|
|
);
|
2022-08-03 18:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="update-snap-permission-list">
|
|
|
|
<NewPermissions />
|
|
|
|
<ApprovedPermissions />
|
|
|
|
<RevokedPermissions />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateSnapPermissionList.propTypes = {
|
|
|
|
/**
|
|
|
|
* Permissions that have already been approved
|
|
|
|
*/
|
|
|
|
approvedPermissions: PropTypes.object.isRequired,
|
|
|
|
/**
|
|
|
|
* Previously used permissions that are now revoked
|
|
|
|
*/
|
|
|
|
revokedPermissions: PropTypes.object.isRequired,
|
|
|
|
/**
|
|
|
|
* New permissions that are being requested
|
|
|
|
*/
|
|
|
|
newPermissions: PropTypes.object.isRequired,
|
|
|
|
};
|