-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2188 from AbdulWahab3181/repo2graph
Create Test button for function nodes
- Loading branch information
Showing
8 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/components/ModalsContainer/CreateBountyModal/Body/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { FormProvider, useForm } from 'react-hook-form' | ||
import { useModal } from '~/stores/useModalStore' | ||
import { useSelectedNode } from '~/stores/useGraphStore' | ||
import { postBountyData } from '~/network/postBounty' | ||
import { useState } from 'react' | ||
import * as React from 'react' | ||
import { CreateBounty } from '../CreateBounty' | ||
|
||
export type FormData = { | ||
nodeType: string | ||
budget: string | ||
} & Partial<{ [k: string]: string }> | ||
|
||
export const Body = () => { | ||
const [errMessage, setErrMessage] = useState<string>('') | ||
const { close } = useModal('createBounty') | ||
const selectedNode = useSelectedNode() | ||
const form = useForm<FormData>({ mode: 'onChange' }) | ||
const { handleSubmit, setValue } = form | ||
|
||
const handleClose = () => { | ||
setValue('budget', '') | ||
setValue('nodeType', '') | ||
close() | ||
} | ||
|
||
const onSubmit = async (data: FormData) => { | ||
const { budget, nodeType } = data | ||
|
||
const nodeData = { name: nodeType } | ||
|
||
const payload = { | ||
type: 'code_generation', | ||
amount: Number(budget), | ||
workspace_uuid: 'ck9drb84nncjnaefo090', | ||
jwt_token: null, | ||
ref_id: selectedNode?.ref_id as string, | ||
node_data: nodeData, | ||
} | ||
|
||
try { | ||
await postBountyData(payload) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (err: any) { | ||
setErrMessage(err) | ||
} finally { | ||
setValue('budget', '') | ||
setValue('nodeType', '') | ||
handleClose() | ||
} | ||
} | ||
|
||
return ( | ||
<FormProvider {...form}> | ||
<form id="create-bounty-form" onSubmit={handleSubmit(onSubmit)}> | ||
<CreateBounty errMessage={errMessage} handleClose={handleClose} /> | ||
</form> | ||
</FormProvider> | ||
) | ||
} |
98 changes: 98 additions & 0 deletions
98
src/components/ModalsContainer/CreateBountyModal/CreateBounty/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Button } from '@mui/material' | ||
import { FC } from 'react' | ||
import styled from 'styled-components' | ||
import { Flex } from '~/components/common/Flex' | ||
import { Text } from '~/components/common/Text' | ||
import { useFormContext } from 'react-hook-form' | ||
import { TextInput } from '~/components/common/TextInput' | ||
import { AutoComplete, TAutocompleteOption } from '~/components/common/AutoComplete' | ||
import { requiredRule } from '~/constants' | ||
|
||
type Props = { | ||
errMessage: string | ||
handleClose: () => void | ||
} | ||
|
||
export const CreateBounty: FC<Props> = ({ errMessage, handleClose }) => { | ||
const { setValue, watch } = useFormContext() | ||
|
||
const watchBudget = watch('budget', '') | ||
const watchNodeType = watch('nodeType', '') | ||
|
||
const onSelect = (val: TAutocompleteOption | null) => { | ||
const selectedValue = val?.label || 'SecondBrain' | ||
|
||
setValue('nodeType', selectedValue, { shouldValidate: true }) | ||
} | ||
|
||
const options = [{ label: 'SecondBrain', value: 'SecondBrain' }] | ||
|
||
const isDisable = !!(watchBudget && watchNodeType) | ||
|
||
return ( | ||
<Flex> | ||
<Flex align="center" direction="row" justify="space-between" mb={18}> | ||
<StyledHeadingText>Create Bounty</StyledHeadingText> | ||
</Flex> | ||
|
||
<Flex mb={20}> | ||
<StyledText>Select Workspace</StyledText> | ||
<AutoComplete autoFocus onSelect={onSelect} options={options} /> | ||
</Flex> | ||
|
||
<Flex mb={20}> | ||
<StyledText>Set Budget</StyledText> | ||
<TextInput | ||
id="budget" | ||
name="budget" | ||
placeholder="Enter budget" | ||
rules={{ | ||
...requiredRule, | ||
pattern: { | ||
value: /^[0-9]+$/, | ||
message: 'Please enter a valid number', | ||
}, | ||
}} | ||
value={watchBudget} | ||
/> | ||
</Flex> | ||
|
||
<Flex direction="row"> | ||
<Flex grow={1}> | ||
<Button color="secondary" onClick={() => handleClose()} size="large" variant="contained"> | ||
Cancel | ||
</Button> | ||
</Flex> | ||
<Flex grow={1} ml={20}> | ||
<Button color="secondary" disabled={!isDisable} size="large" type="submit" variant="contained"> | ||
Confirm | ||
</Button> | ||
</Flex> | ||
</Flex> | ||
{errMessage && <StyledError>{errMessage}</StyledError>} | ||
</Flex> | ||
) | ||
} | ||
|
||
const StyledText = styled(Text)` | ||
font-size: 14px; | ||
font-weight: 600; | ||
font-family: 'Barlow'; | ||
margin-bottom: 6px; | ||
` | ||
|
||
const StyledHeadingText = styled(Text)` | ||
font-size: 18px; | ||
font-weight: 600; | ||
font-family: 'Barlow'; | ||
margin-bottom: 6px; | ||
` | ||
|
||
const StyledError = styled(Flex)` | ||
font-size: 13px; | ||
font-family: Barlow; | ||
color: #ff8f80; | ||
line-height: 0.2px; | ||
margin-top: 12px; | ||
padding-top: 20px; | ||
` |
31 changes: 31 additions & 0 deletions
31
src/components/ModalsContainer/CreateBountyModal/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useForm } from 'react-hook-form' | ||
import { BaseModal, ModalKind } from '~/components/Modal' | ||
import { useModal } from '~/stores/useModalStore' | ||
import * as React from 'react' | ||
|
||
import { Body } from '~/components/ModalsContainer/CreateBountyModal/Body' | ||
|
||
export type FormData = { | ||
nodeType: string | ||
budget: string | ||
} & Partial<{ [k: string]: string }> | ||
|
||
export const CreateBountyModal = () => { | ||
const { close } = useModal('createBounty') | ||
const form = useForm<FormData>({ mode: 'onChange' }) | ||
const { setValue } = form | ||
|
||
const handleClose = () => { | ||
setValue('budget', '') | ||
setValue('nodeType', '') | ||
close() | ||
} | ||
|
||
const modalKind: ModalKind = 'small' | ||
|
||
return ( | ||
<BaseModal id="createBounty" kind={modalKind} onClose={handleClose} preventOutsideClose> | ||
<Body /> | ||
</BaseModal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { api } from '~/network/api' | ||
|
||
type BountyPayload = { | ||
type: string | ||
amount: number | ||
workspace_uuid: string | ||
jwt_token: string | null | ||
ref_id: string | ||
node_data: { | ||
name: string | ||
} | ||
} | ||
|
||
export const postBountyData = async (payload: BountyPayload) => { | ||
const response = await api.post('/bounty', JSON.stringify(payload)) | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters