feat: wired the registeration journey with the api, success modal, reactive data

This commit is contained in:
MTG2000
2022-09-08 14:53:08 +03:00
parent 97d31c3360
commit a0f09aaa33
35 changed files with 878 additions and 118 deletions

View File

@@ -52,6 +52,10 @@ export interface NexusGenInputs {
roles: NexusGenInputs['MakerRoleInput'][]; // [MakerRoleInput!]!
skills: NexusGenInputs['MakerSkillInput'][]; // [MakerSkillInput!]!
}
RegisterInTournamentInput: { // input type
email: string; // String!
hacking_status: NexusGenEnums['TournamentMakerHackingStatusEnum']; // TournamentMakerHackingStatusEnum!
}
StoryInputType: { // input type
body: string; // String!
cover_image?: string | null; // String
@@ -70,6 +74,7 @@ export interface NexusGenEnums {
POST_TYPE: "Bounty" | "Question" | "Story"
RoleLevelEnum: 3 | 0 | 1 | 2 | 4
TournamentEventTypeEnum: 2 | 3 | 0 | 1
TournamentMakerHackingStatusEnum: 1 | 0
VOTE_ITEM_TYPE: "Bounty" | "PostComment" | "Project" | "Question" | "Story" | "User"
}
@@ -428,6 +433,7 @@ export interface NexusGenFieldTypes {
createStory: NexusGenRootTypes['Story'] | null; // Story
deleteStory: NexusGenRootTypes['Story'] | null; // Story
donate: NexusGenRootTypes['Donation']; // Donation!
registerInTournament: NexusGenRootTypes['User'] | null; // User
updateProfileDetails: NexusGenRootTypes['MyProfile'] | null; // MyProfile
updateProfileRoles: NexusGenRootTypes['MyProfile'] | null; // MyProfile
updateUserPreferences: NexusGenRootTypes['MyProfile']; // MyProfile!
@@ -439,6 +445,7 @@ export interface NexusGenFieldTypes {
email: string | null; // String
github: string | null; // String
id: number; // Int!
in_tournament: boolean; // Boolean!
jobTitle: string | null; // String
join_date: NexusGenScalars['Date']; // Date!
lightning_address: string | null; // String
@@ -604,6 +611,7 @@ export interface NexusGenFieldTypes {
email: string | null; // String
github: string | null; // String
id: number; // Int!
in_tournament: boolean; // Boolean!
jobTitle: string | null; // String
join_date: NexusGenScalars['Date']; // Date!
lightning_address: string | null; // String
@@ -639,6 +647,7 @@ export interface NexusGenFieldTypes {
email: string | null; // String
github: string | null; // String
id: number; // Int!
in_tournament: boolean; // Boolean!
jobTitle: string | null; // String
join_date: NexusGenScalars['Date']; // Date!
lightning_address: string | null; // String
@@ -767,6 +776,7 @@ export interface NexusGenFieldTypeNames {
createStory: 'Story'
deleteStory: 'Story'
donate: 'Donation'
registerInTournament: 'User'
updateProfileDetails: 'MyProfile'
updateProfileRoles: 'MyProfile'
updateUserPreferences: 'MyProfile'
@@ -778,6 +788,7 @@ export interface NexusGenFieldTypeNames {
email: 'String'
github: 'String'
id: 'Int'
in_tournament: 'Boolean'
jobTitle: 'String'
join_date: 'Date'
lightning_address: 'String'
@@ -943,6 +954,7 @@ export interface NexusGenFieldTypeNames {
email: 'String'
github: 'String'
id: 'Int'
in_tournament: 'Boolean'
jobTitle: 'String'
join_date: 'Date'
lightning_address: 'String'
@@ -978,6 +990,7 @@ export interface NexusGenFieldTypeNames {
email: 'String'
github: 'String'
id: 'Int'
in_tournament: 'Boolean'
jobTitle: 'String'
join_date: 'Date'
lightning_address: 'String'
@@ -1024,6 +1037,10 @@ export interface NexusGenArgTypes {
donate: { // args
amount_in_sat: number; // Int!
}
registerInTournament: { // args
data?: NexusGenInputs['RegisterInTournamentInput'] | null; // RegisterInTournamentInput
tournament_id: number; // Int!
}
updateProfileDetails: { // args
data?: NexusGenInputs['ProfileDetailsInput'] | null; // ProfileDetailsInput
}
@@ -1039,6 +1056,11 @@ export interface NexusGenArgTypes {
item_type: NexusGenEnums['VOTE_ITEM_TYPE']; // VOTE_ITEM_TYPE!
}
}
MyProfile: {
in_tournament: { // args
id: number; // Int!
}
}
Query: {
allProjects: { // args
skip?: number | null; // Int
@@ -1112,6 +1134,16 @@ export interface NexusGenArgTypes {
id: number; // Int!
}
}
User: {
in_tournament: { // args
id: number; // Int!
}
}
BaseUser: {
in_tournament: { // args
id: number; // Int!
}
}
}
export interface NexusGenAbstractTypeMembers {

View File

@@ -24,6 +24,7 @@ interface BaseUser {
email: String
github: String
id: Int!
in_tournament(id: Int!): Boolean!
jobTitle: String
join_date: Date!
lightning_address: String
@@ -148,6 +149,7 @@ type Mutation {
createStory(data: StoryInputType): Story
deleteStory(id: Int!): Story
donate(amount_in_sat: Int!): Donation!
registerInTournament(data: RegisterInTournamentInput, tournament_id: Int!): User
updateProfileDetails(data: ProfileDetailsInput): MyProfile
updateProfileRoles(data: ProfileRolesInput): MyProfile
updateUserPreferences(userKeys: [UserKeyInputType!]): MyProfile!
@@ -160,6 +162,7 @@ type MyProfile implements BaseUser {
email: String
github: String
id: Int!
in_tournament(id: Int!): Boolean!
jobTitle: String
join_date: Date!
lightning_address: String
@@ -285,6 +288,11 @@ type Question implements PostBase {
votes_count: Int!
}
input RegisterInTournamentInput {
email: String!
hacking_status: TournamentMakerHackingStatusEnum!
}
enum RoleLevelEnum {
Advanced
Beginner
@@ -377,6 +385,11 @@ type TournamentJudge {
name: String!
}
enum TournamentMakerHackingStatusEnum {
OpenToConnect
Solo
}
type TournamentMakersResponse {
hasNext: Boolean
hasPrev: Boolean
@@ -401,6 +414,7 @@ type User implements BaseUser {
email: String
github: String
id: Int!
in_tournament(id: Int!): Boolean!
jobTitle: String
join_date: Date!
lightning_address: String

View File

@@ -345,9 +345,12 @@ const registerInTournament = extendType({
type: 'Mutation',
definition(t) {
t.field('registerInTournament', {
type: 'boolean',
args: { data: RegisterInTournamentInput },
async resolve(_root, { email, hacking_status }, ctx) {
type: 'User',
args: {
data: RegisterInTournamentInput,
tournament_id: nonNull(intArg())
},
async resolve(_root, { tournament_id, data: { email, hacking_status } }, ctx) {
const user = await getUserByPubKey(ctx.userPubKey);
// Do some validation
@@ -359,12 +362,17 @@ const registerInTournament = extendType({
// ....
// ....
prisma.tournamentParticipant.create({
data:{
return (await prisma.tournamentParticipant.create({
data: {
tournament_id,
user_id: user.id,
email,
hacking_status
},
include: {
user: true
}
})
})).user;
}
})
},

View File

@@ -54,8 +54,15 @@ const BaseUser = interfaceType({
})
t.nonNull.list.nonNull.field('tournaments', {
type: Tournament,
resolve: (parent) => {
return []
resolve: async (parent) => {
return prisma.tournamentParticipant.findMany({
where: {
user_id: parent.id
},
include: {
tournament: true
}
}).then(d => d.map(item => item.tournament))
}
})
t.nonNull.list.nonNull.field('similar_makers', {
@@ -82,6 +89,15 @@ const BaseUser = interfaceType({
}
});
t.nonNull.boolean('in_tournament', {
args: {
id: nonNull(intArg())
},
resolve(parent, args) {
return prisma.tournamentParticipant.findFirst({ where: { tournament_id: args.id, user_id: parent.id } }).then(res => !!res)
}
})
},
resolveType() {