/feedbackPage.js Secret
Last active
November 10, 2020 20:40
Star
You must be signed in to star a gist
Redwood transactions and DB writes
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
const FeedbackPage = ({id}) => { | |
const { logIn, logOut, isAuthenticated, currentUser } = useAuth() | |
let { filter } = useParams() | |
const { addMessage } = useFlash() | |
return ( | |
<CoreLayout> | |
<PageHeader title={"Feedback"}/> | |
<div class="px-4 mt-6 sm:px-6 lg:px-8"> | |
<FeedbackListCell teamId={currentUser.currentTeam.id} filter={filter}/> | |
</div> | |
</CoreLayout> | |
) | |
} |
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
export const getCurrentUser = async (decoded, { _token, _type }) => { | |
const account = await db.user.findOne( | |
{ | |
where: {sub: decoded.sub}, | |
include: { | |
currentTeam: true | |
} | |
}, | |
) | |
if (!account) { | |
const newUser = await db.user.create({ | |
data: { | |
email: decoded.email, | |
sub: decoded.sub, | |
} | |
}) | |
const currentUser = { | |
...newUser, | |
currentTeam: null | |
} | |
} | |
const currentUser = { | |
userId: account.id, | |
email: account.email, | |
currentTeam: account.currentTeam, | |
} | |
console.log(currentUser) | |
return { ...currentUser } | |
} |
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
const CREATE_CONTACT = gql` | |
mutation CreateTeamWithNameMutation($input: CreateTeamInput!) { | |
createTeamWithName(input: $input) { | |
id | |
name | |
} | |
} | |
` | |
const PickTeamPage = () => { | |
const { isAuthenticated, currentUser } = useAuth() | |
if (currentUser.currentTeam != null) { | |
return <Redirect to={routes.feedback()} /> | |
} | |
const [create, {loading, error}] = useMutation(CREATE_CONTACT, { | |
onCompleted: async () => { | |
// await new Promise(r => setTimeout(r, 5000)); | |
navigate(routes.feedback()) | |
}, | |
}) | |
const onSubmit = (data) => { | |
create({ variables: { input: data } }) | |
} |
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
export const createTeamWithName = async ({input}) => { | |
requireAuth() | |
const newTeam = await db.team.create({ | |
data: { | |
name: input.name, | |
owner: { | |
connect: {id: context.currentUser.userId} | |
} | |
}, | |
}) | |
return newTeam | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment