Skip to content

Commit

Permalink
fix: zod naming and refacto some logic
Browse files Browse the repository at this point in the history
Signed-off-by: clegirar <[email protected]>
  • Loading branch information
clegirar committed Jan 3, 2025
1 parent ee9ef93 commit 9c80dc7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
ROLES_BASED_ORGANIZATION_STEPS,
RolesFormType,
RolesMembersFormType,
ZodRolesMembersObject,
ZodRolesObject,
zodRolesMembersObject,
zodRolesObject,
} from "@/utils/types/organizations";

export const RolesDeployerSteps: React.FC<{
Expand All @@ -54,7 +54,7 @@ export const RolesDeployerSteps: React.FC<{
const queryClient = useQueryClient();
const { setToast } = useFeedbacks();
const rolesMembersForm = useForm<RolesMembersFormType>({
resolver: zodResolver(ZodRolesMembersObject),
resolver: zodResolver(zodRolesMembersObject),
defaultValues: {
members: selectedWallet?.address
? [
Expand All @@ -68,7 +68,7 @@ export const RolesDeployerSteps: React.FC<{
},
});
const rolesForm = useForm<RolesFormType>({
resolver: zodResolver(ZodRolesObject),
resolver: zodResolver(zodRolesObject),
defaultValues: {
roles: [],
},
Expand All @@ -84,10 +84,6 @@ export const RolesDeployerSteps: React.FC<{

const [configureVotingFormData, setConfigureVotingFormData] =
useState<ConfigureVotingFormType>();
// const [rolesSettingsFormData, setRolesSettingsFormData] =
// useState<RolesSettingFormType>();
// const [memberSettingsFormData, setMemberSettingsFormData] =
// useState<RolesMemberSettingFormType>();

const createDaoContract = async (): Promise<boolean> => {
try {
Expand Down Expand Up @@ -244,6 +240,8 @@ export const RolesDeployerSteps: React.FC<{
);
setOrganizationData(undefined);
setConfigureVotingFormData(undefined);
rolesMembersForm.reset();
rolesForm.reset();
setCurrentStep(0);
setDAOAddress("");
setLaunchingStep(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import { layout } from "@/utils/style/layout";
import {
ROLES_BASED_ORGANIZATION_STEPS,
RolesMembersFormType,
ZodRolesMemberObject,
zodRolesMemberObject,
} from "@/utils/types/organizations";

interface RolesMembersSettingsSectionProps {
members: z.infer<typeof ZodRolesMemberObject>[];
members: z.infer<typeof zodRolesMemberObject>[];
append: UseFieldArrayAppend<RolesMembersFormType>;
control: Control<RolesMembersFormType>;
remove: (index?: number | number[] | undefined) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SpacerColumn, SpacerRow } from "@/components/spacer";
import { neutral33 } from "@/utils/style/colors";
import { fontSemibold18 } from "@/utils/style/fonts";
import { layout } from "@/utils/style/layout";
import { RoleFormType, ZodRoleObject } from "@/utils/types/organizations";
import { RoleFormType, zodRoleObject } from "@/utils/types/organizations";

interface RolesModalCreateRoleProps {
modalVisible: boolean;
Expand All @@ -27,7 +27,7 @@ export const RolesModalCreateRole: React.FC<RolesModalCreateRoleProps> = ({
addRoleField,
}) => {
const { control, handleSubmit, reset } = useForm<RoleFormType>({
resolver: zodResolver(ZodRoleObject),
resolver: zodResolver(zodRoleObject),
});

const getInitialState = () => {
Expand Down Expand Up @@ -118,9 +118,9 @@ export const RolesModalCreateRole: React.FC<RolesModalCreateRoleProps> = ({
finalResources = finalResources?.concat(resource.resources);
}
});
reset();
setResources(getInitialState());
addRoleField(data.name, data.color, finalResources);
reset();
})}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import { layout, screenContentMaxWidthLarge } from "@/utils/style/layout";
import {
ROLES_BASED_ORGANIZATION_STEPS,
RolesFormType,
ZodRoleObject,
zodRoleObject,
} from "@/utils/types/organizations";

interface RolesSettingsSectionProps {
roles: z.infer<typeof ZodRoleObject>[];
roles: z.infer<typeof zodRoleObject>[];
remove: (index?: number | number[] | undefined) => void;
append: UseFieldArrayAppend<RolesFormType>;
handleSubmit: () => void;
Expand Down
56 changes: 20 additions & 36 deletions packages/utils/types/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,6 @@ export type ConfigureVotingFormType = {
minutes: string;
};

export const ZodRoleObject = z.object({
name: z.string().trim().min(1),
color: z.string().trim().min(1),
resources: z.array(z.string()),
});
export const ZodRolesMemberObject = z.object({
addr: z.string().trim().min(1),
weight: z.string().trim().min(1),
// TODO: change it to an array
roles: z.string(),
});
export const ZodRolesObject = z.object({
roles: z.array(ZodRoleObject),
});
export const ZodRolesMembersObject = z.object({
members: z.array(ZodRolesMemberObject),
});
const ZodRolesConfigObject = z.object({
supportPercent: z.number(),
minimumApprovalPercent: z.number(),
days: z.string().trim(),
hours: z.string().trim(),
minutes: z.string().trim(),
});
export type RolesConfigFormType = z.infer<typeof ZodRolesConfigObject>;
export type RolesMembersFormType = z.infer<typeof ZodRolesMembersObject>;
export type RolesFormType = z.infer<typeof ZodRolesObject>;
export type RoleFormType = z.infer<typeof ZodRoleObject>;

export type LaunchingProcessStepType = {
title: string;
completeText: string;
Expand All @@ -72,13 +43,26 @@ export type MembershipMemberSettingFormType = {

// ROLES BASED ORGANIZATION FORM TYPES

export type RolesSettingFormType = {
roles: { name: string; color: string; resources: string[] | undefined }[];
};

export type RolesMemberSettingFormType = {
members: { addr: string; weight: string; roles: string | undefined }[];
};
export const zodRoleObject = z.object({
name: z.string().trim().min(1),
color: z.string().trim().min(1),
resources: z.array(z.string()).optional(),
});
export const zodRolesObject = z.object({
roles: z.array(zodRoleObject),
});
export const zodRolesMemberObject = z.object({
addr: z.string().trim().min(1),
weight: z.string().trim().min(1),
// TODO: change it to an array
roles: z.string(),
});
export const zodRolesMembersObject = z.object({
members: z.array(zodRolesMemberObject),
});
export type RolesMembersFormType = z.infer<typeof zodRolesMembersObject>;
export type RolesFormType = z.infer<typeof zodRolesObject>;
export type RoleFormType = z.infer<typeof zodRoleObject>;

// TOKEN BASED ORGANIZATION FORM TYPES

Expand Down

0 comments on commit 9c80dc7

Please sign in to comment.