Merge pull request #11 from Irev-Dev/route-to-ide-from-edit
Route to ide from edit
This commit was merged in pull request #11.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { useMutation, useFlash } from '@redwoodjs/web'
|
import { useMutation } from '@redwoodjs/web'
|
||||||
import { navigate, routes } from '@redwoodjs/router'
|
|
||||||
import PartForm from 'src/components/PartForm'
|
import PartForm from 'src/components/PartForm'
|
||||||
|
|
||||||
export const QUERY = gql`
|
export const QUERY = gql`
|
||||||
@@ -26,17 +25,9 @@ const UPDATE_PART_MUTATION = gql`
|
|||||||
export const Loading = () => <div>Loading...</div>
|
export const Loading = () => <div>Loading...</div>
|
||||||
|
|
||||||
export const Success = ({ part }) => {
|
export const Success = ({ part }) => {
|
||||||
const { addMessage } = useFlash()
|
const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION)
|
||||||
const [updatePart, { loading, error }] = useMutation(UPDATE_PART_MUTATION, {
|
|
||||||
onCompleted: () => {
|
|
||||||
navigate(routes.parts())
|
|
||||||
addMessage('Part updated.', { classes: 'rw-flash-success' })
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const onSave = (input, id) => {
|
const onSave = (input, id) => updatePart({ variables: { id, input } })
|
||||||
updatePart({ variables: { id, input } })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PartForm part={part} onSave={onSave} error={error} loading={loading} />
|
<PartForm part={part} onSave={onSave} error={error} loading={loading} />
|
||||||
|
|||||||
@@ -8,16 +8,27 @@ import {
|
|||||||
Submit,
|
Submit,
|
||||||
} from '@redwoodjs/forms'
|
} from '@redwoodjs/forms'
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { navigate, routes } from '@redwoodjs/router'
|
||||||
|
import { useFlash } from '@redwoodjs/web'
|
||||||
|
|
||||||
import Editor from "rich-markdown-editor";
|
import Editor from "rich-markdown-editor";
|
||||||
|
|
||||||
const PartForm = (props) => {
|
const PartForm = (props) => {
|
||||||
|
const { addMessage } = useFlash()
|
||||||
const [description, setDescription] = useState(props?.part?.description)
|
const [description, setDescription] = useState(props?.part?.description)
|
||||||
const onSubmit = (data) => {
|
const onSubmit = async (data, e) => {
|
||||||
props.onSave({
|
|
||||||
|
await props.onSave({
|
||||||
...data,
|
...data,
|
||||||
description,
|
description,
|
||||||
}, props?.part?.id)
|
}, props?.part?.id)
|
||||||
|
const shouldOpenIde = e?.nativeEvent?.submitter?.dataset?.openIde
|
||||||
|
if(shouldOpenIde) {
|
||||||
|
navigate(routes.partIde({id: props?.part?.id}))
|
||||||
|
} else {
|
||||||
|
navigate(routes.part({id: props?.part?.id}))
|
||||||
|
}
|
||||||
|
addMessage('Part updated.', { classes: 'rw-flash-success' })
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -80,6 +91,9 @@ const PartForm = (props) => {
|
|||||||
<Submit disabled={props.loading} className="rw-button rw-button-blue">
|
<Submit disabled={props.loading} className="rw-button rw-button-blue">
|
||||||
Save
|
Save
|
||||||
</Submit>
|
</Submit>
|
||||||
|
<Submit disabled={props.loading} data-open-ide={true} className="rw-button rw-button-blue">
|
||||||
|
Save and open IDE
|
||||||
|
</Submit>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user