-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: select point estimate from frontend
- Loading branch information
1 parent
a07970e
commit bca5934
Showing
5 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
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,74 @@ | ||
import React, { useRef } from 'react'; | ||
import { useQuery, useMutation } from 'urql'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { ReduxState } from '~redux/reducers'; | ||
|
||
const getValidEstimates = `query GetValidEstimates($projectId: String!) { | ||
pointingSchema(projectId: $projectId) { | ||
... on EstimateSchema { | ||
all | ||
} | ||
... on DbError { | ||
message | ||
} | ||
... on PtError { | ||
code | ||
error | ||
kind | ||
possibleFix | ||
} | ||
} | ||
}`; | ||
|
||
const addEstimate = `mutation AddStoryEstimate($storyId: String!, $pointValue: Int!, $userEmail: String!) { | ||
createEstimate(storyId: $storyId, pointValue: $pointValue, userEmail: $userEmail) { | ||
id | ||
pointValue | ||
userId | ||
} | ||
}`; | ||
|
||
interface Props { | ||
storyId: string; | ||
} | ||
|
||
const EstimateSelect = ({ storyId }: Props) => { | ||
const currentProject = useSelector((state: ReduxState) => state.project); | ||
const currentUser = useSelector((state: ReduxState) => state.user); | ||
|
||
const [, executeMutation] = useMutation(addEstimate); | ||
|
||
const onChange = e => { | ||
executeMutation({ | ||
storyId, | ||
pointValue: parseInt(e.target.value, 10), | ||
userEmail: currentUser.email, | ||
}); | ||
}; | ||
|
||
const [res] = useQuery({ | ||
query: getValidEstimates, | ||
variables: { projectId: currentProject.id }, | ||
}); | ||
|
||
if (res.fetching) { | ||
return <>Loading GraphQL...</>; | ||
} else if (res.error) { | ||
return <>GraphQL Error</>; | ||
} | ||
|
||
return ( | ||
<select onChange={onChange}> | ||
{res.data.pointingSchema.all.map((value: number) => { | ||
return ( | ||
<option key={value} value={value}> | ||
{value} | ||
</option> | ||
); | ||
})} | ||
</select> | ||
); | ||
}; | ||
|
||
export default EstimateSelect; |
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
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