mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-01-20 19:57:55 -05:00
feat: support for editing roles on quests
This commit is contained in:
@@ -0,0 +1 @@
|
||||
ALTER TABLE "public"."quest_role" ALTER COLUMN "rank" SET NOT NULL;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE "public"."quest_role" ALTER COLUMN "rank" DROP NOT NULL;
|
||||
@@ -106,7 +106,14 @@ const getDefaultFormValues = (
|
||||
}))
|
||||
: [],
|
||||
// fix this
|
||||
roles: [],
|
||||
roles: editQuest
|
||||
? editQuest.quest_roles
|
||||
.map((s) => s.PlayerRole)
|
||||
.map((s) => ({
|
||||
value: s.role,
|
||||
label: s.label,
|
||||
}))
|
||||
: [],
|
||||
});
|
||||
|
||||
type FieldProps = {
|
||||
|
||||
@@ -5,6 +5,7 @@ export const UpdateQuestMutation = gql`
|
||||
$id: uuid!
|
||||
$input: quest_set_input!
|
||||
$skills: [quest_skill_insert_input!]!
|
||||
$roles: [quest_role_insert_input!]!
|
||||
) {
|
||||
update_quest_by_pk(pk_columns: { id: $id }, _set: $input) {
|
||||
id
|
||||
@@ -19,5 +20,15 @@ export const UpdateQuestMutation = gql`
|
||||
skill_id
|
||||
}
|
||||
}
|
||||
delete_quest_role(where: { quest_id: { _eq: $id } }) {
|
||||
affected_rows
|
||||
}
|
||||
insert_quest_role(objects: $roles) {
|
||||
affected_rows
|
||||
returning {
|
||||
quest_id
|
||||
role
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import { Heading, LoadingState, useToast } from '@metafam/ds';
|
||||
import { convertToRaw } from 'draft-js';
|
||||
import draftToHtml from 'draftjs-to-html';
|
||||
import {
|
||||
GuildFragmentFragment,
|
||||
PlayerRole,
|
||||
QuestFragmentFragment,
|
||||
useUpdateQuestMutation,
|
||||
} from 'graphql/autogen/types';
|
||||
import { getSsrClient } from 'graphql/client';
|
||||
import { getQuest } from 'graphql/getQuest';
|
||||
import { getPlayerRoles } from 'graphql/queries/enums/getRoles';
|
||||
import { getSkills } from 'graphql/queries/enums/getSkills';
|
||||
import { getGuilds } from 'graphql/queries/guild';
|
||||
import { GetStaticPaths, GetStaticPropsContext } from 'next';
|
||||
import { useRouter } from 'next/router';
|
||||
import React from 'react';
|
||||
@@ -11,14 +21,6 @@ import {
|
||||
CreateQuestFormInputs,
|
||||
QuestForm,
|
||||
} from '../../../components/Quest/QuestForm';
|
||||
import {
|
||||
GuildFragmentFragment,
|
||||
QuestFragmentFragment,
|
||||
useUpdateQuestMutation,
|
||||
} from '../../../graphql/autogen/types';
|
||||
import { getSsrClient } from '../../../graphql/client';
|
||||
import { getSkills } from '../../../graphql/queries/enums/getSkills';
|
||||
import { getGuilds } from '../../../graphql/queries/guild';
|
||||
import { useUser } from '../../../lib/hooks';
|
||||
import { transformCooldownForBackend } from '../../../utils/questHelpers';
|
||||
import { CategoryOption, parseSkills } from '../../../utils/skillHelpers';
|
||||
@@ -27,9 +29,15 @@ type Props = {
|
||||
quest: QuestFragmentFragment;
|
||||
guilds: GuildFragmentFragment[];
|
||||
skillChoices: Array<CategoryOption>;
|
||||
roleChoices: Array<PlayerRole>;
|
||||
};
|
||||
|
||||
const EditQuestPage: React.FC<Props> = ({ quest, skillChoices, guilds }) => {
|
||||
const EditQuestPage: React.FC<Props> = ({
|
||||
quest,
|
||||
skillChoices,
|
||||
roleChoices,
|
||||
guilds,
|
||||
}) => {
|
||||
useUser({ redirectTo: '/quests' });
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
@@ -46,14 +54,22 @@ const EditQuestPage: React.FC<Props> = ({ quest, skillChoices, guilds }) => {
|
||||
cooldown: transformCooldownForBackend(data.cooldown, data.repetition),
|
||||
status: data.status,
|
||||
};
|
||||
|
||||
const skillsObjects = data.skills.map((s) => ({
|
||||
quest_id: quest.id,
|
||||
skill_id: s.id,
|
||||
}));
|
||||
|
||||
const rolesObjects = data.roles.map((s) => ({
|
||||
quest_id: quest.id,
|
||||
role: s.value,
|
||||
}));
|
||||
|
||||
updateQuest({
|
||||
id: quest.id,
|
||||
input: updateQuestInput,
|
||||
skills: skillsObjects,
|
||||
roles: rolesObjects,
|
||||
}).then((res) => {
|
||||
if (res.data?.update_quest_by_pk && !res.error) {
|
||||
router.push(`/quest/${quest.id}`);
|
||||
@@ -91,8 +107,7 @@ const EditQuestPage: React.FC<Props> = ({ quest, skillChoices, guilds }) => {
|
||||
<QuestForm
|
||||
guilds={guilds}
|
||||
skillChoices={skillChoices}
|
||||
// roleChoices={roleChoices}
|
||||
roleChoices={[]}
|
||||
roleChoices={roleChoices}
|
||||
onSubmit={onSubmit}
|
||||
success={!!updateQuestResult.data}
|
||||
fetching={updateQuestResult.fetching}
|
||||
@@ -129,12 +144,14 @@ export const getStaticProps = async (
|
||||
const guilds = await getGuilds();
|
||||
const skills = await getSkills();
|
||||
const skillChoices = parseSkills(skills);
|
||||
const roleChoices = await getPlayerRoles();
|
||||
|
||||
return {
|
||||
props: {
|
||||
quest,
|
||||
guilds,
|
||||
skillChoices,
|
||||
roleChoices,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
|
||||
@@ -65,14 +65,9 @@ const CreateQuestPage: React.FC<Props> = ({
|
||||
roles_id: roles.map((r) => r.value),
|
||||
};
|
||||
|
||||
console.log(input);
|
||||
|
||||
// return;
|
||||
|
||||
createQuest({
|
||||
input,
|
||||
}).then((response) => {
|
||||
console.log('response', response);
|
||||
const createQuestResponse = response.data?.createQuest;
|
||||
if (createQuestResponse?.success) {
|
||||
router.push(`/quest/${createQuestResponse.quest_id}`);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { PlayerRole } from '../graphql/autogen/types';
|
||||
|
||||
export type RoleMap = {
|
||||
[category: string]: CategoryOption;
|
||||
};
|
||||
|
||||
export type RoleOption = PlayerRole & {
|
||||
export type RoleOption = {
|
||||
value: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user