From 129c502516b276ced7bba7b330d70e7f9dbeea2f Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Thu, 22 Oct 2020 14:40:45 +0300 Subject: [PATCH] select country via dropdown --- components/Flag.tsx | 26 -------------------- graphql/schema/index.ts | 4 +-- graphql/schema/user.ts | 14 +++++------ nexus-typegen.ts | 11 +-------- pages/_app.tsx | 1 + scenes/Profile/components/AvatarWithInfo.tsx | 8 ++++-- scenes/Profile/components/ProfileModal.tsx | 19 ++++++++++++++ 7 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 components/Flag.tsx diff --git a/components/Flag.tsx b/components/Flag.tsx deleted file mode 100644 index b03237d0f..000000000 --- a/components/Flag.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { useTranslation } from "lib/useMockT"; -import React from "react"; - -interface FlagProps { - code: string; - size?: "16" | "32"; -} - -const Flag: React.FC = ({ code, size = "16" }) => { - const { t } = useTranslation(); - return ( - {t(`countries;${code.toUpperCase()}`)} - ); -}; - -export default Flag; diff --git a/graphql/schema/index.ts b/graphql/schema/index.ts index 9419bebe6..70bb87405 100644 --- a/graphql/schema/index.ts +++ b/graphql/schema/index.ts @@ -1,4 +1,4 @@ -import { fieldAuthorizePlugin, makeSchema } from "@nexus/schema"; +import { makeSchema } from "@nexus/schema"; import * as userTypes from "graphql/schema/user"; import { nexusSchemaPrisma } from "nexus-plugin-prisma/schema"; import path from "path"; @@ -6,7 +6,7 @@ import path from "path"; export const schema = makeSchema({ types: [userTypes], // FIXME: set complexity plugin - plugins: [nexusSchemaPrisma(), fieldAuthorizePlugin()], + plugins: [nexusSchemaPrisma()], outputs: { // FIXME: should be in graphql/generated instead root schema: path.join(process.cwd(), "schema.graphql"), diff --git a/graphql/schema/user.ts b/graphql/schema/user.ts index e13566601..cd2e6ea1f 100644 --- a/graphql/schema/user.ts +++ b/graphql/schema/user.ts @@ -107,9 +107,6 @@ export const Mutation = mutationType({ args: { profile: arg({ type: UpdateUserProfileInput, required: true }), }, - authorize: async (_root, _args, ctx) => { - return true; - }, resolve: async (_root, args, ctx) => { const user = await getMySession(ctx.req); if (!user) throw Error("Not logged in"); @@ -123,10 +120,15 @@ export const Mutation = mutationType({ }, }); - if (profileWithSameCustomUrl) throw Error("Custom URL already taken"); + if ( + profileWithSameCustomUrl && + profileWithSameCustomUrl.userId !== user.id + ) + throw Error("Custom URL already taken"); } const argsForDb = { + ...args.profile, // can't set array as undefined or null -> need to use [] instead due to how prisma does things weaponPool: args.profile?.weaponPool ? args.profile.weaponPool : [], customUrlPath: args.profile?.customUrlPath @@ -138,7 +140,6 @@ export const Mutation = mutationType({ twitchName: args.profile?.twitchName ? args.profile.twitchName.toLowerCase() : null, - ...args.profile?.weaponPool, }; // FIXME: set custom url to lowerCase @@ -148,8 +149,7 @@ export const Mutation = mutationType({ ...argsForDb, }, update: { - ...args.profile, - weaponPool: args.profile?.weaponPool ? args.profile.weaponPool : [], + ...argsForDb, }, where: { userId: user.id }, }); diff --git a/nexus-typegen.ts b/nexus-typegen.ts index d3b66d734..f1ecffb0b 100644 --- a/nexus-typegen.ts +++ b/nexus-typegen.ts @@ -5,7 +5,7 @@ import * as Context from "./graphql/context" import * as Prisma from ".prisma/client" -import { FieldAuthorizeResolver } from "@nexus/schema/dist/plugins/fieldAuthorizePlugin" + declare global { @@ -144,15 +144,6 @@ declare global { interface NexusGenPluginTypeConfig { } interface NexusGenPluginFieldConfig { - /** - * Authorization for an individual field. Returning "true" - * or "Promise" means the field can be accessed. - * Returning "false" or "Promise" will respond - * with a "Not Authorized" error for the field. - * Returning or throwing an error will also prevent the - * resolver from executing. - */ - authorize?: FieldAuthorizeResolver } interface NexusGenPluginSchemaConfig { } diff --git a/pages/_app.tsx b/pages/_app.tsx index ca6897a67..1eaeecd24 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -24,6 +24,7 @@ const extendedTheme = extendTheme({ // 3) input styling // 4) focus color // 5) form label bolded + // 6) dropdown border + focus colors components: { Button: { defaultProps: { diff --git a/scenes/Profile/components/AvatarWithInfo.tsx b/scenes/Profile/components/AvatarWithInfo.tsx index 98f4b2f9d..8ce9fc9d4 100644 --- a/scenes/Profile/components/AvatarWithInfo.tsx +++ b/scenes/Profile/components/AvatarWithInfo.tsx @@ -1,7 +1,7 @@ import { Avatar, Box, Flex, Heading, IconButton } from "@chakra-ui/core"; -import Flag from "components/Flag"; import Section from "components/Section"; import WeaponImage from "components/WeaponImage"; +import { getEmojiFlag } from "countries-list"; import { GetUserByIdentifierQuery } from "generated/graphql"; import { useTranslation } from "lib/useMockT"; import { useMyTheme } from "lib/useMyTheme"; @@ -52,7 +52,11 @@ const AvatarWithInfo: React.FC = ({ user }) => { {user.fullUsername} - {user.profile?.country && } + {user.profile?.country && ( + + {getEmojiFlag(user.profile.country)} + + )} diff --git a/scenes/Profile/components/ProfileModal.tsx b/scenes/Profile/components/ProfileModal.tsx index 72485cf01..e08cd7cf7 100644 --- a/scenes/Profile/components/ProfileModal.tsx +++ b/scenes/Profile/components/ProfileModal.tsx @@ -14,9 +14,11 @@ import { ModalFooter, ModalHeader, ModalOverlay, + Select, useToast, } from "@chakra-ui/core"; import { zodResolver } from "@hookform/resolvers/zod"; +import { countries } from "countries-list"; import { GetUserByIdentifierQuery, UpdateUserProfileInput, @@ -165,6 +167,23 @@ const ProfileModal: React.FC = ({ {errors.youtubeId?.message} + + + {t("users;Country")} + +