Skip to content

Commit

Permalink
feat(app subscription): change the button activation (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhigarg-bmw authored Oct 31, 2023
1 parent c896eb0 commit a06c87c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

- App Subscription
- Autosetup Process Worker implementation (adjust overlay)
- Usermanagement
- User Invite IdP connection logic

Expand Down
2 changes: 2 additions & 0 deletions src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@
"activateBtn": "Activate",
"configureBtn": "Configure",
"pleaseEnterValidURL": "Please enter a valid URL",
"error": "Error",
"success": "Success",
"tabs": {
"request": "Request",
"active": "Active",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@
"activateBtn": "Activate",
"configureBtn": "Configure",
"pleaseEnterValidURL": "Please enter a valid URL",
"error": "Error",
"success": "Success",
"tabs": {
"request": "Request",
"active": "Active",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@
border-radius: 15px;
padding: 5px;
}
.configureBtn {
pointer-events: none;
}
.statusIcon {
height: 30px;
float: right;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
type CompanySubscriptionData,
ProcessStep,
type SubscriptionContent,
useActivateSubscriptionMutation,
} from 'features/appSubscription/appSubscriptionApiSlice'
import NoItems from 'components/pages/NoItems'
import './Subscription.scss'
Expand All @@ -44,6 +45,7 @@ import { SubscriptionTypes } from '.'
import { getAssetBase } from 'services/EnvironmentService'
import AddTaskIcon from '@mui/icons-material/AddTask'
import HistoryIcon from '@mui/icons-material/History'
import { error, success } from 'services/NotifyService'

type ViewDetail = {
appId: string
Expand Down Expand Up @@ -146,6 +148,17 @@ export default function SubscriptionElements({
const [subscriptionDetail, setSubscriptionDetail] =
useState<SubscriptionDataType>(SubscriptionInitialData)

const [activateSubscription] = useActivateSubscriptionMutation()

const handleActivate = async (subscriptionId: string) => {
try {
await activateSubscription(subscriptionId).unwrap()
success(t('content.appSubscription.success'))
} catch (err) {
error(t('content.appSubscription.error'), '', err as object)
}
}

if (subscriptions && subscriptions.length === 0 && isSuccess) {
return <NoItems />
} else if (!isSuccess) {
Expand Down Expand Up @@ -176,21 +189,6 @@ export default function SubscriptionElements({
label={t('content.appSubscription.configureBtn')}
type="plain"
variant="filled"
className="configureBtn"
/>
<HistoryIcon className="statusIcon pending" />
</>
)
} else if (
subscriptionData.processStepTypeId === ProcessStep.ACTIVATE_SUBSCRIPTION
) {
return (
<>
<Chip
color="primary"
label={t('content.appSubscription.activateBtn')}
type="plain"
variant="filled"
onClick={() => {
type === SubscriptionTypes.APP_SUBSCRIPTION
? setSubscriptionDetail({
Expand All @@ -215,6 +213,21 @@ export default function SubscriptionElements({
<HistoryIcon className="statusIcon pending" />
</>
)
} else if (
subscriptionData.processStepTypeId === ProcessStep.ACTIVATE_SUBSCRIPTION
) {
return (
<>
<Chip
color="primary"
label={t('content.appSubscription.activateBtn')}
type="plain"
variant="filled"
onClick={() => handleActivate(subscription.subscriptionId)}
/>
<HistoryIcon className="statusIcon pending" />
</>
)
} else {
return (
<img
Expand Down
7 changes: 7 additions & 0 deletions src/features/appSubscription/appSubscriptionApiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ export const apiSlice = createApi({
body: data.body,
}),
}),
activateSubscription: builder.mutation<void, string>({
query: (subscriptionId) => ({
url: `/subscription/${subscriptionId}/activate `,
method: 'PUT',
}),
}),
}),
})

Expand All @@ -196,4 +202,5 @@ export const {
useFetchTechnicalProfilesQuery,
useAddUserSubscribtionMutation,
useUpdateTenantUrlMutation,
useActivateSubscriptionMutation,
} = apiSlice

0 comments on commit a06c87c

Please sign in to comment.