Handle cookie banner version sync on updates
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -86,6 +86,14 @@ const publishMutation = graphql`
|
|||||||
version
|
version
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
cookieBanner {
|
||||||
|
id
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -108,7 +116,9 @@ export default function CookieBannerConfigLayout({ queryRef }: CookieBannerConfi
|
|||||||
const banner = data.node;
|
const banner = data.node;
|
||||||
|
|
||||||
const [commitActivate, isActivating] = useMutation<CookieBannerConfigLayoutActivateMutation>(activateMutation);
|
const [commitActivate, isActivating] = useMutation<CookieBannerConfigLayoutActivateMutation>(activateMutation);
|
||||||
const [commitDeactivate, isDeactivating] = useMutation<CookieBannerConfigLayoutDeactivateMutation>(deactivateMutation);
|
const [commitDeactivate, isDeactivating] = useMutation<CookieBannerConfigLayoutDeactivateMutation>(
|
||||||
|
deactivateMutation,
|
||||||
|
);
|
||||||
const [commitPublish, isPublishing] = useMutation<CookieBannerConfigLayoutPublishMutation>(publishMutation);
|
const [commitPublish, isPublishing] = useMutation<CookieBannerConfigLayoutPublishMutation>(publishMutation);
|
||||||
|
|
||||||
const handleToggleState = () => {
|
const handleToggleState = () => {
|
||||||
@@ -164,7 +174,22 @@ export default function CookieBannerConfigLayout({ queryRef }: CookieBannerConfi
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={banner.name}
|
title={(
|
||||||
|
<div className="align-baseline">
|
||||||
|
{banner.name}
|
||||||
|
{banner.latestVersion?.version != null && (
|
||||||
|
<span className="font-mono text-base text-txt-secondary ml-2">
|
||||||
|
v
|
||||||
|
{banner.latestVersion.version}
|
||||||
|
{banner.latestVersion.state === "DRAFT" && (
|
||||||
|
<span className="text-xs font-sans">
|
||||||
|
(draft)
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
description={banner.origin}
|
description={banner.origin}
|
||||||
>
|
>
|
||||||
<Badge variant={banner.state === "ACTIVE" ? "success" : "danger"}>
|
<Badge variant={banner.state === "ACTIVE" ? "success" : "danger"}>
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ const updateBannerMutation = graphql`
|
|||||||
privacyPolicyUrl
|
privacyPolicyUrl
|
||||||
consentExpiryDays
|
consentExpiryDays
|
||||||
consentMode
|
consentMode
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,14 @@ const createMutation = graphql`
|
|||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cookieBanner {
|
||||||
|
id
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -50,6 +50,14 @@ const deleteCategoryMutation = graphql`
|
|||||||
) {
|
) {
|
||||||
deleteCookieCategory(input: $input) {
|
deleteCookieCategory(input: $input) {
|
||||||
deletedCookieCategoryId @deleteEdge(connections: $connections)
|
deletedCookieCategoryId @deleteEdge(connections: $connections)
|
||||||
|
cookieBanner {
|
||||||
|
id
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -69,6 +77,14 @@ const updateCategoryMutation = graphql`
|
|||||||
}
|
}
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
|
cookieBanner {
|
||||||
|
id
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ const updateCategoryMutation = graphql`
|
|||||||
}
|
}
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
|
cookieBanner {
|
||||||
|
id
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -69,6 +69,14 @@ const updateCategoryMutation = graphql`
|
|||||||
}
|
}
|
||||||
updatedAt
|
updatedAt
|
||||||
}
|
}
|
||||||
|
cookieBanner {
|
||||||
|
id
|
||||||
|
latestVersion {
|
||||||
|
id
|
||||||
|
version
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -309,6 +309,12 @@ func (r *mutationResolver) PublishCookieBannerVersion(ctx context.Context, input
|
|||||||
return nil, gqlutils.Internal(ctx)
|
return nil, gqlutils.Internal(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
banner, err := r.cookieBanner.GetCookieBanner(ctx, scope, input.CookieBannerID)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.ErrorCtx(ctx, "cannot get cookie banner", log.Error(err))
|
||||||
|
return nil, gqlutils.Internal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
return &types.PublishCookieBannerVersionPayload{
|
return &types.PublishCookieBannerVersionPayload{
|
||||||
CookieBannerVersion: &types.CookieBannerVersion{
|
CookieBannerVersion: &types.CookieBannerVersion{
|
||||||
ID: version.ID,
|
ID: version.ID,
|
||||||
@@ -317,6 +323,7 @@ func (r *mutationResolver) PublishCookieBannerVersion(ctx context.Context, input
|
|||||||
CreatedAt: version.CreatedAt,
|
CreatedAt: version.CreatedAt,
|
||||||
UpdatedAt: version.UpdatedAt,
|
UpdatedAt: version.UpdatedAt,
|
||||||
},
|
},
|
||||||
|
CookieBanner: types.NewCookieBanner(banner),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +370,15 @@ func (r *mutationResolver) CreateCookieCategory(ctx context.Context, input types
|
|||||||
return nil, gqlutils.Internal(ctx)
|
return nil, gqlutils.Internal(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
banner, err := r.cookieBanner.GetCookieBanner(ctx, scope, input.CookieBannerID)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.ErrorCtx(ctx, "cannot get cookie banner", log.Error(err))
|
||||||
|
return nil, gqlutils.Internal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
return &types.CreateCookieCategoryPayload{
|
return &types.CreateCookieCategoryPayload{
|
||||||
CookieCategoryEdge: types.NewCookieCategoryEdge(category, coredata.CookieCategoryOrderFieldRank),
|
CookieCategoryEdge: types.NewCookieCategoryEdge(category, coredata.CookieCategoryOrderFieldRank),
|
||||||
|
CookieBanner: types.NewCookieBanner(banner),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,8 +425,16 @@ func (r *mutationResolver) UpdateCookieCategory(ctx context.Context, input types
|
|||||||
return nil, gqlutils.Internal(ctx)
|
return nil, gqlutils.Internal(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bannerScope := coredata.NewScopeFromObjectID(category.CookieBannerID)
|
||||||
|
banner, err := r.cookieBanner.GetCookieBanner(ctx, bannerScope, category.CookieBannerID)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.ErrorCtx(ctx, "cannot get cookie banner", log.Error(err))
|
||||||
|
return nil, gqlutils.Internal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
return &types.UpdateCookieCategoryPayload{
|
return &types.UpdateCookieCategoryPayload{
|
||||||
CookieCategory: types.NewCookieCategory(category),
|
CookieCategory: types.NewCookieCategory(category),
|
||||||
|
CookieBanner: types.NewCookieBanner(banner),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +446,18 @@ func (r *mutationResolver) DeleteCookieCategory(ctx context.Context, input types
|
|||||||
|
|
||||||
scope := coredata.NewScopeFromObjectID(input.CookieCategoryID)
|
scope := coredata.NewScopeFromObjectID(input.CookieCategoryID)
|
||||||
|
|
||||||
err := r.cookieBanner.DeleteCookieCategory(ctx, scope, input.CookieCategoryID)
|
category, err := r.cookieBanner.GetCookieCategory(ctx, scope, input.CookieCategoryID)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, cookiebanner.ErrCategoryNotFound) {
|
||||||
|
return nil, gqlutils.NotFound(ctx, err)
|
||||||
|
}
|
||||||
|
r.logger.ErrorCtx(ctx, "cannot get cookie category", log.Error(err))
|
||||||
|
return nil, gqlutils.Internal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
bannerID := category.CookieBannerID
|
||||||
|
|
||||||
|
err = r.cookieBanner.DeleteCookieCategory(ctx, scope, input.CookieCategoryID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, cookiebanner.ErrCategoryNotFound) {
|
if errors.Is(err, cookiebanner.ErrCategoryNotFound) {
|
||||||
return nil, gqlutils.NotFound(ctx, err)
|
return nil, gqlutils.NotFound(ctx, err)
|
||||||
@@ -436,8 +469,16 @@ func (r *mutationResolver) DeleteCookieCategory(ctx context.Context, input types
|
|||||||
return nil, gqlutils.Internal(ctx)
|
return nil, gqlutils.Internal(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bannerScope := coredata.NewScopeFromObjectID(bannerID)
|
||||||
|
banner, err := r.cookieBanner.GetCookieBanner(ctx, bannerScope, bannerID)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.ErrorCtx(ctx, "cannot get cookie banner", log.Error(err))
|
||||||
|
return nil, gqlutils.Internal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
return &types.DeleteCookieCategoryPayload{
|
return &types.DeleteCookieCategoryPayload{
|
||||||
DeletedCookieCategoryID: input.CookieCategoryID,
|
DeletedCookieCategoryID: input.CookieCategoryID,
|
||||||
|
CookieBanner: types.NewCookieBanner(banner),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -254,16 +254,20 @@ type DeactivateCookieBannerPayload {
|
|||||||
|
|
||||||
type PublishCookieBannerVersionPayload {
|
type PublishCookieBannerVersionPayload {
|
||||||
cookieBannerVersion: CookieBannerVersion!
|
cookieBannerVersion: CookieBannerVersion!
|
||||||
|
cookieBanner: CookieBanner!
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateCookieCategoryPayload {
|
type CreateCookieCategoryPayload {
|
||||||
cookieCategoryEdge: CookieCategoryEdge!
|
cookieCategoryEdge: CookieCategoryEdge!
|
||||||
|
cookieBanner: CookieBanner!
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCookieCategoryPayload {
|
type UpdateCookieCategoryPayload {
|
||||||
cookieCategory: CookieCategory!
|
cookieCategory: CookieCategory!
|
||||||
|
cookieBanner: CookieBanner!
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteCookieCategoryPayload {
|
type DeleteCookieCategoryPayload {
|
||||||
deletedCookieCategoryId: ID!
|
deletedCookieCategoryId: ID!
|
||||||
|
cookieBanner: CookieBanner!
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user