Skip to content

Commit 05bade2

Browse files
refactor: license validation condition
1 parent 2f2182a commit 05bade2

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

assets/apps/dashboard/src/Components/Content/Sidebar/LicenseCard.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ const LicenseCard = () => {
2828
const { valid, expiration } = license;
2929
const { whiteLabel, strings } = neveDash;
3030
const { licenseCardHeading, licenseCardDescription } = strings;
31+
const isValid = 'valid' === valid;
3132

3233
const toggleLicense = () => {
33-
const toDo = 'valid' === valid ? 'deactivate' : 'activate';
34+
const toDo = isValid ? 'deactivate' : 'activate';
3435
setStatus('activate' === toDo ? 'activating' : 'deactivating');
3536
send(proApi + '/toggle_license', { key, action: toDo }).then(
3637
(response) => {
@@ -48,11 +49,10 @@ const LicenseCard = () => {
4849
);
4950
};
5051

51-
if (whiteLabel && whiteLabel.hideLicense && 'valid' === valid) {
52+
if (whiteLabel && whiteLabel.hideLicense && isValid) {
5253
return null;
5354
}
5455

55-
const isValid = 'valid' === valid;
5656
const isOrWasValid = ['valid', 'active_expired', 'expired'].includes(valid);
5757

5858
const getStatusLabel = () => {
@@ -64,9 +64,7 @@ const LicenseCard = () => {
6464
};
6565

6666
if (!status) {
67-
return isValid
68-
? __('Deactivate', 'neve')
69-
: __('Activate', 'neve');
67+
return isValid ? __('Deactivate', 'neve') : __('Activate', 'neve');
7068
}
7169

7270
return statusLabelMap[status];
@@ -109,8 +107,8 @@ const LicenseCard = () => {
109107
placeholder={__('Enter License Key', 'neve')}
110108
/>
111109
<Button
112-
isPrimary={'valid' !== valid}
113-
isSecondary={'valid' === valid}
110+
isPrimary={!isValid}
111+
isSecondary={isValid}
114112
disabled={!!status || !key}
115113
isSubmit
116114
>
@@ -127,10 +125,10 @@ const LicenseCard = () => {
127125
{isOrWasValid && (
128126
<div className="flex items-center gap-1">
129127
<Pill
130-
type={valid === 'valid' ? 'success' : 'warning'}
128+
type={isValid ? 'success' : 'warning'}
131129
className="inline-flex items-center gap-1 px-2 py-1"
132130
>
133-
{valid === 'valid' ? (
131+
{isValid ? (
134132
<>
135133
<LucideCircleCheck size={14} />
136134
<span>{__('Valid', 'neve')}</span>
@@ -146,7 +144,7 @@ const LicenseCard = () => {
146144
<>
147145
<span className="space-x-1 ml-auto">
148146
<span className="text-xs">
149-
{'valid' === valid
147+
{isValid
150148
? __('Expires', 'neve')
151149
: __('Expired', 'neve')}
152150
</span>

0 commit comments

Comments
 (0)