From 40f7ce0f97b8ab409ba8df9b3d7b4e43df21683b Mon Sep 17 00:00:00 2001 From: "Malin J." Date: Mon, 28 Oct 2024 10:04:48 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20to=20tailwi?= =?UTF-8?q?nd=20#2569=20(#2570)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️ refactor to tailwind #2569 * ✏️ Small adjustment to negative margin #2569 --- web/components/src/Accordion/Item.tsx | 8 ++------ .../topicPages/Form/CareerFairForm.tsx | 20 ++++--------------- web/pageComponents/topicPages/Form/Form.tsx | 14 +++---------- .../careersContactForm/CareersContactForm.tsx | 8 ++------ 4 files changed, 11 insertions(+), 39 deletions(-) diff --git a/web/components/src/Accordion/Item.tsx b/web/components/src/Accordion/Item.tsx index d2a12c27b..54d69b8df 100644 --- a/web/components/src/Accordion/Item.tsx +++ b/web/components/src/Accordion/Item.tsx @@ -1,9 +1,5 @@ -import styled from 'styled-components' import { AccordionItem } from '@chakra-ui/react' -const StyledItem = styled(AccordionItem)` - border-bottom: 1px solid var(--grey-40); -` export type AccordionItemProps = { id: number children: React.ReactNode @@ -11,8 +7,8 @@ export type AccordionItemProps = { export const Item = ({ id, children, ...rest }: AccordionItemProps) => { return ( - + {children} - + ) } diff --git a/web/pageComponents/topicPages/Form/CareerFairForm.tsx b/web/pageComponents/topicPages/Form/CareerFairForm.tsx index afa006fac..446a7cf91 100644 --- a/web/pageComponents/topicPages/Form/CareerFairForm.tsx +++ b/web/pageComponents/topicPages/Form/CareerFairForm.tsx @@ -11,7 +11,6 @@ import { FormSubmitSuccessBox, FormSubmitFailureBox, } from '@components' -import styled from 'styled-components' import { BaseSyntheticEvent, useState } from 'react' import FriendlyCaptcha from './FriendlyCaptcha' @@ -27,15 +26,6 @@ type FormValues = { preferredLang: string } -const StyledHelper = styled.p` - margin-top: calc(var(--space-small) * -1); - font-size: var(--typeScale-0); -` - -const StyledCheckBox = styled(Checkbox)` - padding-bottom: var(--space-medium); -` - const CareerFairForm = () => { const intl = useIntl() const [submitButtonEnabled, setSubmitButtonEnabled] = useState(false) @@ -264,13 +254,13 @@ const CareerFairForm = () => { id: 'career_fair_form_visit_equinor', defaultMessage: 'Would like to visit Equinor office or facility', }) && ( - +

{intl.formatMessage({ id: 'career_fair_form_visit_equinor_helper_text', defaultMessage: 'Please be aware that we only offer visits to a few selected locations. Please specify your preferred location and we will revert to you as soon as we can.', })} - +

)} )} @@ -319,10 +309,8 @@ const CareerFairForm = () => { /> )} /> -
- -
- { const { title, ingress, downloads } = data @@ -37,9 +29,9 @@ const Form = ({ data, anchor, className }: { data: FormData; anchor?: string; cl <> <> {downloads && ( - +
{downloads.length > 0 && } - +
)} @@ -50,7 +42,7 @@ const Form = ({ data, anchor, className }: { data: FormData; anchor?: string; cl return (
- {title && } + {title && } {ingress && } {renderForm(variant)} diff --git a/web/pageComponents/topicPages/Form/careersContactForm/CareersContactForm.tsx b/web/pageComponents/topicPages/Form/careersContactForm/CareersContactForm.tsx index 3b1bb7d2d..36c3053e6 100644 --- a/web/pageComponents/topicPages/Form/careersContactForm/CareersContactForm.tsx +++ b/web/pageComponents/topicPages/Form/careersContactForm/CareersContactForm.tsx @@ -13,7 +13,6 @@ import { } from '@components' import { BaseSyntheticEvent, useState } from 'react' import FriendlyCaptcha from '../FriendlyCaptcha' -import styled from 'styled-components' import getCatalogType from './getRequestType' type FormValues = { @@ -28,10 +27,6 @@ type FormValues = { supportingDocuments: string } -const StyledCheckBox = styled(Checkbox)` - padding-bottom: var(--space-medium); -` - const CareersContactForm = () => { const intl = useIntl() const [submitButtonEnabled, setSubmitButtonEnabled] = useState(false) @@ -363,7 +358,8 @@ const CareersContactForm = () => {
- Date: Tue, 29 Oct 2024 14:32:14 +0530 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20Fix=20never=20finishing=20pu?= =?UTF-8?q?blish=20action=20#2587?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanityv3/actions/CustomPublishAction.ts | 124 +++++++++--------------- sanityv3/sanity.config.tsx | 7 +- 2 files changed, 52 insertions(+), 79 deletions(-) diff --git a/sanityv3/actions/CustomPublishAction.ts b/sanityv3/actions/CustomPublishAction.ts index a5426c991..cb8eecbdd 100644 --- a/sanityv3/actions/CustomPublishAction.ts +++ b/sanityv3/actions/CustomPublishAction.ts @@ -1,84 +1,56 @@ -import { useState } from 'react' -import { - DocumentActionComponent, - DocumentActionConfirmDialogProps, - DocumentActionDescription, - DocumentActionProps, - DocumentActionsContext, - SanityClient, -} from 'sanity' -import { apiVersion } from '../sanity.client' -import { useToast } from '@sanity/ui' +import { useState, useEffect } from 'react' +import { DocumentActionConfirmDialogProps, DocumentActionProps, useDocumentOperation } from 'sanity' const FIRST_PUBLISHED_AT_FIELD_NAME = 'firstPublishedAt' const LAST_MODIFIED_AT_FIELD_NAME = 'lastModifiedAt' -const requiresConfirm = ['news', 'localNews'] -const requiresFirstPublished = ['news', 'localNews'] +export function SetAndPublishAction(props: DocumentActionProps) { + const { patch, publish } = useDocumentOperation(props.id, props.type) + const [isPublishing, setIsPublishing] = useState(false) + const [dialogOpen, setDialogOpen] = useState(false) -const updateCustomPublishFields = async (id: string, client: SanityClient, setFirstPublish: boolean) => { - const currentTimeStamp = new Date().toISOString() - const patch = client.patch(id).set({ [LAST_MODIFIED_AT_FIELD_NAME]: currentTimeStamp }) - if (setFirstPublish) patch.set({ [FIRST_PUBLISHED_AT_FIELD_NAME]: currentTimeStamp }) - - await patch.commit().catch((e) => { - throw e - }) -} - -export function createCustomPublishAction(originalAction: DocumentActionComponent, context: DocumentActionsContext) { - const client = context.getClient({ apiVersion: apiVersion }) - return (props: DocumentActionProps) => { - const [dialogOpen, setDialogOpen] = useState(false) - const originalResult = originalAction(props as DocumentActionProps) as DocumentActionDescription - const toast = useToast() - - const handlePublish = async () => { - try { - if (requiresFirstPublished.includes(props.type)) { - await updateCustomPublishFields( - props.draft?._id || props.id, - client, - !props.published?.[FIRST_PUBLISHED_AT_FIELD_NAME], - ) - } - originalResult.onHandle && originalResult.onHandle() - setDialogOpen(false) - } catch (e) { - console.error(e) - toast.push({ - duration: 7000, - status: 'error', - title: 'Failed to publish, you probably miss the mutation token. Check console for details.', - }) - setDialogOpen(false) - } - } - - const confirmationBox = requiresConfirm.includes(props.type) - ? { - onHandle: () => { - setDialogOpen(true) - }, - dialog: - dialogOpen && - props.draft && - ({ - type: 'confirm', - onCancel: () => { - props.onComplete() - setDialogOpen(false) - }, - onConfirm: handlePublish, - message: 'Are you sure you want to publish?', - } as DocumentActionConfirmDialogProps), - } - : {} - - return { - ...originalResult, - onHandle: handlePublish, - ...confirmationBox, + useEffect(() => { + // if the isPublishing state was set to true and the draft has changed + // to become `null` the document has been published + if (isPublishing && !props.draft) { + setIsPublishing(false) } + }, [props.draft]) + + return { + disabled: publish.disabled || dialogOpen, + label: isPublishing ? 'Publishing…' : `Publish`, + onHandle: () => { + // This will update the button text + setDialogOpen(true) + }, + dialog: + dialogOpen && + props.draft && + ({ + type: 'confirm', + onCancel: () => { + props.onComplete() + setDialogOpen(false) + }, + onConfirm: () => { + const currentTimeStamp = new Date().toISOString() + // set lastModifiedAt date. + patch.execute([{ set: { [LAST_MODIFIED_AT_FIELD_NAME]: currentTimeStamp } }]) + + //set firstPublishedAt date if not published. + if (!props.published?.[FIRST_PUBLISHED_AT_FIELD_NAME]) + patch.execute([{ set: { [FIRST_PUBLISHED_AT_FIELD_NAME]: currentTimeStamp } }]) + + // Perform the publish + publish.execute() + + // Signal that the action is completed + props.onComplete() + + setDialogOpen(false) + }, + message: 'Are you sure you want to publish?', + } as DocumentActionConfirmDialogProps), } } diff --git a/sanityv3/sanity.config.tsx b/sanityv3/sanity.config.tsx index a26be3c4c..f18899dc1 100644 --- a/sanityv3/sanity.config.tsx +++ b/sanityv3/sanity.config.tsx @@ -8,7 +8,8 @@ import { PluginOptions, SchemaTypeDefinition, Template, - buildLegacyTheme } from 'sanity' + buildLegacyTheme, +} from 'sanity' import type { InputProps, @@ -27,7 +28,7 @@ import { DeleteTranslationAction } from './actions/customDelete/DeleteTranslatio import { documentInternationalization } from '@equinor/document-internationalization' import { FotowareAssetSource } from './plugins/asset-source-fotoware' import { BrandmasterAssetSource } from './plugins/asset-source-brandmaster' -import { createCustomPublishAction } from './actions/CustomPublishAction' +import { SetAndPublishAction } from './actions/PublishAction' import { dataset, projectId } from './sanity.client' import { DatabaseIcon } from '@sanity/icons' import { crossDatasetDuplicator } from '@sanity/cross-dataset-duplicator' @@ -123,7 +124,7 @@ const getConfig = (datasetParam: string, projectIdParam: string, isSecret = fals .map((originalAction) => { switch (originalAction.action) { case 'publish': - return createCustomPublishAction(originalAction, context) + return ['news', 'localNews'].includes(context.schemaType) ? SetAndPublishAction : originalAction case 'duplicate': return createCustomDuplicateAction(originalAction) default: From e78c891cbef70d39983990017fae3e6e11185ada Mon Sep 17 00:00:00 2001 From: Padmaja <52911293+padms@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:32:58 +0530 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20#2587?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sanityv3/sanity.config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanityv3/sanity.config.tsx b/sanityv3/sanity.config.tsx index f18899dc1..1de64c04c 100644 --- a/sanityv3/sanity.config.tsx +++ b/sanityv3/sanity.config.tsx @@ -28,7 +28,7 @@ import { DeleteTranslationAction } from './actions/customDelete/DeleteTranslatio import { documentInternationalization } from '@equinor/document-internationalization' import { FotowareAssetSource } from './plugins/asset-source-fotoware' import { BrandmasterAssetSource } from './plugins/asset-source-brandmaster' -import { SetAndPublishAction } from './actions/PublishAction' +import { SetAndPublishAction } from './actions/CustomPublishAction' import { dataset, projectId } from './sanity.client' import { DatabaseIcon } from '@sanity/icons' import { crossDatasetDuplicator } from '@sanity/cross-dataset-duplicator'