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
|
||||
state
|
||||
}
|
||||
cookieBanner {
|
||||
id
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -108,7 +116,9 @@ export default function CookieBannerConfigLayout({ queryRef }: CookieBannerConfi
|
||||
const banner = data.node;
|
||||
|
||||
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 handleToggleState = () => {
|
||||
@@ -164,7 +174,22 @@ export default function CookieBannerConfigLayout({ queryRef }: CookieBannerConfi
|
||||
/>
|
||||
|
||||
<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}
|
||||
>
|
||||
<Badge variant={banner.state === "ACTIVE" ? "success" : "danger"}>
|
||||
|
||||
@@ -43,6 +43,11 @@ const updateBannerMutation = graphql`
|
||||
privacyPolicyUrl
|
||||
consentExpiryDays
|
||||
consentMode
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,14 @@ const createMutation = graphql`
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
cookieBanner {
|
||||
id
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -50,6 +50,14 @@ const deleteCategoryMutation = graphql`
|
||||
) {
|
||||
deleteCookieCategory(input: $input) {
|
||||
deletedCookieCategoryId @deleteEdge(connections: $connections)
|
||||
cookieBanner {
|
||||
id
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -69,6 +77,14 @@ const updateCategoryMutation = graphql`
|
||||
}
|
||||
updatedAt
|
||||
}
|
||||
cookieBanner {
|
||||
id
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -48,6 +48,14 @@ const updateCategoryMutation = graphql`
|
||||
}
|
||||
updatedAt
|
||||
}
|
||||
cookieBanner {
|
||||
id
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -69,6 +69,14 @@ const updateCategoryMutation = graphql`
|
||||
}
|
||||
updatedAt
|
||||
}
|
||||
cookieBanner {
|
||||
id
|
||||
latestVersion {
|
||||
id
|
||||
version
|
||||
state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -309,6 +309,12 @@ func (r *mutationResolver) PublishCookieBannerVersion(ctx context.Context, input
|
||||
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{
|
||||
CookieBannerVersion: &types.CookieBannerVersion{
|
||||
ID: version.ID,
|
||||
@@ -317,6 +323,7 @@ func (r *mutationResolver) PublishCookieBannerVersion(ctx context.Context, input
|
||||
CreatedAt: version.CreatedAt,
|
||||
UpdatedAt: version.UpdatedAt,
|
||||
},
|
||||
CookieBanner: types.NewCookieBanner(banner),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -363,8 +370,15 @@ func (r *mutationResolver) CreateCookieCategory(ctx context.Context, input types
|
||||
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{
|
||||
CookieCategoryEdge: types.NewCookieCategoryEdge(category, coredata.CookieCategoryOrderFieldRank),
|
||||
CookieBanner: types.NewCookieBanner(banner),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -411,8 +425,16 @@ func (r *mutationResolver) UpdateCookieCategory(ctx context.Context, input types
|
||||
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{
|
||||
CookieCategory: types.NewCookieCategory(category),
|
||||
CookieBanner: types.NewCookieBanner(banner),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -424,7 +446,18 @@ func (r *mutationResolver) DeleteCookieCategory(ctx context.Context, input types
|
||||
|
||||
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 errors.Is(err, cookiebanner.ErrCategoryNotFound) {
|
||||
return nil, gqlutils.NotFound(ctx, err)
|
||||
@@ -436,8 +469,16 @@ func (r *mutationResolver) DeleteCookieCategory(ctx context.Context, input types
|
||||
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{
|
||||
DeletedCookieCategoryID: input.CookieCategoryID,
|
||||
CookieBanner: types.NewCookieBanner(banner),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -254,16 +254,20 @@ type DeactivateCookieBannerPayload {
|
||||
|
||||
type PublishCookieBannerVersionPayload {
|
||||
cookieBannerVersion: CookieBannerVersion!
|
||||
cookieBanner: CookieBanner!
|
||||
}
|
||||
|
||||
type CreateCookieCategoryPayload {
|
||||
cookieCategoryEdge: CookieCategoryEdge!
|
||||
cookieBanner: CookieBanner!
|
||||
}
|
||||
|
||||
type UpdateCookieCategoryPayload {
|
||||
cookieCategory: CookieCategory!
|
||||
cookieBanner: CookieBanner!
|
||||
}
|
||||
|
||||
type DeleteCookieCategoryPayload {
|
||||
deletedCookieCategoryId: ID!
|
||||
cookieBanner: CookieBanner!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user