feat(rbac): resolved submit button getting disabled

This commit is contained in:
Akhil Mohan
2023-09-08 21:22:36 +05:30
parent 91c1aca588
commit 2f9b35b2f9
@@ -337,10 +337,21 @@ export const DashboardPage = () => {
permission.cannot( permission.cannot(
ProjectPermissionActions.Create, ProjectPermissionActions.Create,
subject(ProjectPermissionSub.Secrets, { environment, secretPath }) subject(ProjectPermissionSub.Secrets, { environment, secretPath })
) &&
permission.cannot(
ProjectPermissionActions.Delete,
subject(ProjectPermissionSub.Secrets, { environment, secretPath })
); );
const canDoRollback = !isReadOnly; const canDoRollback = !isReadOnly;
const isSubmitDisabled = isReadOnly || (!isRollbackMode && !isDirty) || isSubmitting; const isSubmitDisabled =
isReadOnly ||
// not in rollback mode and no form has changed
(!isRollbackMode && !isDirty) ||
// in rollback mode and don't have permission to do it
(isRollbackMode &&
permission.cannot(ProjectPermissionActions.Create, ProjectPermissionSub.SecretRollback)) ||
isSubmitting;
useEffect(() => { useEffect(() => {
if (!isSnapshotChanging && Boolean(snapshotId)) { if (!isSnapshotChanging && Boolean(snapshotId)) {
@@ -455,7 +466,6 @@ export const DashboardPage = () => {
await onSecretRollback(); await onSecretRollback();
return; return;
} }
console.log(userSec);
// just closing this if save is triggered from drawer // just closing this if save is triggered from drawer
handlePopUpClose("secretDetails"); handlePopUpClose("secretDetails");
// encrypt and format the secrets to batch api format // encrypt and format the secrets to batch api format
@@ -471,7 +481,6 @@ export const DashboardPage = () => {
reset(); reset();
return; return;
} }
console.log(batchedSecret);
try { try {
await batchSecretOp({ await batchSecretOp({
requests: batchedSecret, requests: batchedSecret,
@@ -990,24 +999,15 @@ export const DashboardPage = () => {
Go back Go back
</Button> </Button>
)} )}
<ProjectPermissionCan
I={ <Tooltip
isRollbackMode isOpen={
? ProjectPermissionActions.Create !isSubmitting && isSubmitDisabled && isReadOnly && !isDirty ? undefined : false
: (ProjectPermissionActions.Edit as any)
}
a={
isRollbackMode
? ProjectPermissionSub.SecretRollback
: subject(ProjectPermissionSub.Secrets, {
environment,
secretPath
})
} }
content="Access restricted"
> >
{(isAllowed) => (
<Button <Button
isDisabled={isSubmitDisabled || !isAllowed} isDisabled={isSubmitDisabled}
isLoading={isSubmitting} isLoading={isSubmitting}
leftIcon={<FontAwesomeIcon icon={isRollbackMode ? faClockRotateLeft : faCheck} />} leftIcon={<FontAwesomeIcon icon={isRollbackMode ? faClockRotateLeft : faCheck} />}
onClick={handleSubmit(onSaveSecret)} onClick={handleSubmit(onSaveSecret)}
@@ -1017,8 +1017,7 @@ export const DashboardPage = () => {
> >
{isRollbackMode ? "Rollback" : "Save Changes"} {isRollbackMode ? "Rollback" : "Save Changes"}
</Button> </Button>
)} </Tooltip>
</ProjectPermissionCan>
</div> </div>
</div> </div>
<div <div