Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
mariojsnunes committed Oct 11, 2024
1 parent 0c0a021 commit ab0ffce
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/cypress/src/support/db/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { generateDBEndpoints } from 'oa-shared'
// React apps populate a process variable, however it might not always be accessible outside
// (e.g. cypress will instead use it's own env to populate a prefix)
const process = globalThis.process || ({} as any)
const e = process.env || ({} as any)
const e = import.meta.env || process.env || ({} as any)

/**
* A prefix can be used to simplify large-scale schema changes or multisite hosting
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Howto/Content/Common/Howto.form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const HowtoForm = observer((props: IProps) => {
showInvalidFileWarning:
props.formValues.files?.length > 0 && props.formValues.fileLink,
})
const [howtoSlug, setHowtoSlug] = useState<string>('')

const { formValues, parentType } = props
const { fileEditMode, showSubmitModal, showInvalidFileWarning } = state
Expand Down Expand Up @@ -100,7 +101,8 @@ export const HowtoForm = observer((props: IProps) => {
: IModerationStatus.AWAITING_MODERATION
}
logger.debug('submitting form', formValues)
await howtoStore.uploadHowTo(formValues)
const howto = await howtoStore.uploadHowTo(formValues)
setHowtoSlug(howto?.slug || '')
form.reset(formValues)
}
// automatically generate the slug when the title changes
Expand All @@ -116,6 +118,7 @@ export const HowtoForm = observer((props: IProps) => {
{showSubmitModal && (
<HowToSubmitStatus
{...props}
slug={howtoSlug}
onClose={() => {
setState((state) => ({ ...state, showSubmitModal: false }))
howtoStore.resetUploadStatus()
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Howto/Content/Common/SubmitStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { useNavigate } from '@remix-run/react'
import { observer } from 'mobx-react'
import { Button, Icon, Modal } from 'oa-components'
Expand All @@ -8,6 +7,7 @@ import { Box, Flex, Heading, Text } from 'theme-ui'
import { buttons, headings } from '../../labels'

interface IProps {
slug: string
onClose: () => void
}

Expand Down Expand Up @@ -46,7 +46,7 @@ const HowToSubmitStatus = observer((props: IProps) => {
variant={!uploadStatus.Complete ? 'disabled' : 'outline'}
icon="arrow-forward"
onClick={() => {
navigate('/how-to/' + howtoStore.activeHowto!.slug)
navigate('/how-to/' + props.slug)
props.onClose()
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const HowtoDescription = ({ howto, loggedInUser, ...props }: IProps) => {
trackEvent({
category: 'How-To',
action: 'Deleted',
label: stores.howtoStore.activeHowto?.title,
label: howto.title,
})
logger.debug(
{
category: 'How-To',
action: 'Deleted',
label: stores.howtoStore.activeHowto?.title,
label: howto.title,
},
'How-to marked for deletion',
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Question/Content/Common/QuestionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export const QuestionForm = (props: IProps) => {
mutators={{ setAllowDraftSaveFalse }}
initialValues={formValues}
render={({ submitting, handleSubmit, pristine, valid, values }) => {
const numberOfImageInputsAvailable = values?.images
? Math.min(values.images.length + 1, QUESTION_MAX_IMAGES)
const numberOfImageInputsAvailable = (values as any)?.images
? Math.min((values as any).images.length + 1, QUESTION_MAX_IMAGES)
: 1

return (
Expand Down
14 changes: 10 additions & 4 deletions src/stores/Howto/howto.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ export class HowtoStore extends ModuleStore {
}

// upload a new or update an existing how-to
public async uploadHowTo(values: IHowtoFormInput | IHowtoDB) {
public async uploadHowTo(
values: IHowtoFormInput | IHowtoDB,
): Promise<IHowtoDB | null> {
logger.debug('uploading howto', { values })
this.updateUploadStatus('Start')
// create a reference either to the existing document (if editing) or a new document if creating
Expand All @@ -224,6 +226,8 @@ export class HowtoStore extends ModuleStore {
logger.debug('uploadHowto.existingDoc', { existingDoc })

const user = this.activeUser as IUser

let howto: IHowtoDB | null = null
try {
// upload any pending images, avoid trying to re-upload images previously saved
// if cover already uploaded stored as object not array
Expand Down Expand Up @@ -265,7 +269,7 @@ export class HowtoStore extends ModuleStore {
const keywords = getKeywords(values.title + ' ' + values.description)
keywords.push(_createdBy)

const howTo: IHowto = {
const howToData: IHowto = {
...(existingDoc || {}),
_id,
_createdBy,
Expand All @@ -292,9 +296,9 @@ export class HowtoStore extends ModuleStore {
...(time ? { time } : {}),
}

logger.debug('populating database', howTo)
logger.debug('populating database', howToData)
// set the database document
await this.updateHowtoItem(howTo, true)
howto = await this.updateHowtoItem(howToData, true)
this.updateUploadStatus('Database')
logger.debug('post added')
// complete
Expand All @@ -303,6 +307,8 @@ export class HowtoStore extends ModuleStore {
logger.error('error', error)
throw new Error(error.message)
}

return howto
}

private async addCommentNotification(howto: IHowto) {
Expand Down

0 comments on commit ab0ffce

Please sign in to comment.