Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: roles form missing image upload and empty wallet address bug #2305

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web-components/src/components/image-crop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default function ImageCrop({
*/
const onLoad = useCallback(
(img: HTMLImageElement) => {
console.log(img);
imgRef.current = img;
const imgWidth = img.width;
const imgHeight = img.height;
Expand Down Expand Up @@ -152,7 +153,7 @@ export default function ImageCrop({
onComplete={setCompletedCrop}
circularCrop={circularCrop}
crossorigin="anonymous"
imageStyle={{ maxHeight: mobileMatches ? 380 : 500 }}
imageStyle={{ width: '100%', maxHeight: mobileMatches ? 380 : 500 }}
/>
</div>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Props {
fixedCrop?: Partial<Crop>;
children: ReactNode;
setValue: (value: string) => void;
onUpload?: (imageFile: File) => Promise<string>;
onUpload?: (imageFile: File) => Promise<string | undefined>;
sx?: {
label?: SxProps<Theme>;
button?: SxProps<Theme>;
Expand Down
13 changes: 13 additions & 0 deletions web-marketplace/src/components/organisms/RolesForm/RolesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import OnBoardingCard from 'web-components/src/components/cards/OnBoardingCard';
import EditIcon from 'web-components/src/components/icons/EditIcon';
import TextField from 'web-components/src/components/inputs/new/TextField/TextField';

import { apiUri } from 'lib/apiUri';
import { errorBannerTextAtom } from 'lib/atoms/error.atoms';
import { useAuth } from 'lib/auth/auth';
import { getAccountByAddrQuery } from 'lib/queries/react-query/registry-server/graphql/getAccountByAddrQuery/getAccountByAddrQuery';
Expand All @@ -31,17 +32,20 @@ import { ProfileModalSchemaType } from './components/ProfileModal/ProfileModal.s
import { RoleField } from './components/RoleField/RoleField';
import { useSaveProfile } from './hooks/useSaveProfile';
import { rolesFormSchema, RolesFormSchemaType } from './RolesForm.schema';
import { useHandleUpload } from '../MediaForm/hooks/useHandleUpload';

interface RolesFormProps {
submit: (props: RoleSubmitProps) => Promise<void>;
onNext?: () => void;
onPrev?: () => void;
initialValues?: RolesFormSchemaType;
isOnChain: boolean;
projectId?: string;
}

const RolesForm: React.FC<React.PropsWithChildren<RolesFormProps>> = ({
initialValues,
projectId,
submit,
onNext,
onPrev,
Expand Down Expand Up @@ -127,6 +131,13 @@ const RolesForm: React.FC<React.PropsWithChildren<RolesFormProps>> = ({

const saveProfile = useSaveProfile();

const [offChainProjectId, setOffChainProjectId] = useState(projectId);
const { handleUpload } = useHandleUpload({
offChainProjectId,
apiServerUrl: apiUri,
setOffChainProjectId,
});

return (
<Form
form={form}
Expand Down Expand Up @@ -160,6 +171,7 @@ const RolesForm: React.FC<React.PropsWithChildren<RolesFormProps>> = ({
accounts={accountsProjectDeveloper}
saveProfile={saveProfile}
activeAccountId={activeAccountId}
onUpload={handleUpload}
{...form.register('projectDeveloper')}
/>
<RoleField
Expand All @@ -174,6 +186,7 @@ const RolesForm: React.FC<React.PropsWithChildren<RolesFormProps>> = ({
accounts={accountsVerifier}
saveProfile={saveProfile}
activeAccountId={activeAccountId}
onUpload={handleUpload}
{...form.register('verifier')}
/>
{isOnChain && admin && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const profileModalSchema = z.object({
id: z.string().optional(),
creatorId: z.string().nullable().optional(),
profileType: z.custom<AccountType>(),
name: z.string(),
name: z.string().min(1),
profileImage: z.string(),
description: z.string().max(160).optional(),
address: optionalAddressSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ProfileModalProps {
initialValues?: ProfileModalSchemaType;
onClose: () => void;
onSubmit: (profile: ProfileModalSchemaType) => void;
onUpload?: (imageFile: File) => Promise<string>;
onUpload?: (imageFile: File) => Promise<string | undefined>;
}

function ProfileModal({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AddNewProfile: React.FC<AddNewProfileProps> = ({
profileType: AccountType.User,
name: '',
profileImage: DEFAULT_PROFILE_USER_AVATAR,
address: null,
});
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface Props {
profile: ProfileModalSchemaType,
initialValue?: ProfileModalSchemaType | null,
) => Promise<{ id: string; creatorId: string } | undefined>;
onUpload?: (imageFile: File) => Promise<string | undefined>;
}

export const RoleField = forwardRef<HTMLInputElement, Props>(
Expand All @@ -67,6 +68,7 @@ export const RoleField = forwardRef<HTMLInputElement, Props>(
accounts,
saveProfile,
activeAccountId,
onUpload,
}: Props,
ref,
) => {
Expand Down Expand Up @@ -210,6 +212,7 @@ export const RoleField = forwardRef<HTMLInputElement, Props>(
{profileAdd && (
<ProfileModal
initialValues={profileAdd}
onUpload={onUpload}
onClose={closeProfileModal}
onSubmit={async profile => {
const account = await saveProfile(profile);
Expand Down
1 change: 1 addition & 0 deletions web-marketplace/src/pages/Roles/Roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const Roles: React.FC<React.PropsWithChildren<unknown>> = () => {
isOnChain={
!editContextLoading && !!onChainProject && !!wallet?.address
}
projectId={offChainProject?.id}
/>
</WithLoader>
</ProjectFormTemplate>
Expand Down
Loading