Each quest can have many types of rewards, most of them are stream lined and require no action from Frontend, but for some other specific types like prizes, there are some additional actions requird.
Different types of Quest Rewards
Give Resources
Give Assets
Give Prizes
Give Discord Roles
Each of the above rewards can be identified and dealt with in FE from the following data types:
In the Quest object, look for the rewardfield. Depending on the reward defined in the admin panel, we need to use the field slugto identify the type of reward. in the SDK you will find the following zod schemas you can use to validate/identify rewards:
Of course if you don't want to opt-in to zod, you can also use plain typescript to identify these rewards with:
export type CreditResourceType = z.infer<typeof giveResourceRewardSchema>;
export type AssignDiscordRoleType = z.infer<
typeof assignDiscordRoleRewardSchema
>;
export type ManualClaimRewardType = z.infer<typeof manualClaimRewardSchema>;
export type GivePrizesRewardType = z.infer<typeof givePrizesRewardSchema>;
export type GiveAssetsType = z.infer<typeof giveAssetsRewardSchema>;
export type GiveResourcesProgressive = z.infer<
typeof giveResourceProgressiveRewardSchema
>;
Claiming Rewards
Quest reward allocation is manual and require a user action to claim rewards once their quest is completed. Once the quest is completed, use the following methods to identify rewards allocated to the user to prepare for the claim phase:
The above function will fetch all reward allocations for the given quest id per user. Remember to populate Authorization headers in the axios config beforehand.
In client components
In the client components use the following hook to receive all rewards allocated to the user. an enabled option is provided to pass in when the quest is completed.
function useQuestRewardAllocations(
questId?: string,
options?: Partial<{ enabled: boolean }>,
);
Claiming Rewards
Once you have the reward allocation, you can start claiming the rewards by checking whether or not a reward has a requirement, currently only one reward types might have requirements, but you can streamline this by checking the requirementsfield in the allocation.
If there is no requirement, the claiming process is easy as what follows:
NOTE: the payload field is not required when there is no requirement, it is mainly used for passing requirements.
Claiming Prizes
Since prizes are custom rewards, their delivery mechanism is a bit different, some of them are automatically distributed, but some other require admin approval. In addition to that, custom rewards may require some additional information from the user before they can be delivered. For example, a Steam gift card may require email address from the user, or for some other prizes a postal address may be required. This information is defined in the requirements field.
In the following section we will deal with prize requirements and how can we prepare data to send to our API.
Currently following requirements are supported via SDK:
Then we can identify required fields based on the type definitions we cover previously, note that this example is using react-hook-form, but you can use any form library you prefer:
Note: data.email might be empty, but if it has value, it means the user has already populated this information, and it can be re-used as a default value.
Once you gather all required information, you can pass these information in the format of Record<string, string | Record<string, string>> as the payloadargument we've discussed above in the claiming rewards section.
Determining prize status
Once the claim is completed, make sure you are hooking to distributionStatusfield in the allocation entity.
Note: Only when the status is QUEST_REWARD_DISTRIBUTION_STATUS.DISTRIBUTEDyou can assume that the reward is delivered, otherwise, the reward is pending in the queue to be delivered.