Skip to content

Commit

Permalink
Merge branch 'andrew_testing' into fix-add-item-modal-close
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-bierman authored Apr 2, 2024
2 parents f4305bd + 260185b commit 1ec7325
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 115 deletions.
3 changes: 1 addition & 2 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@
"togpx": "^0.5.4",
"uuid": "3.4.0",
"xmldom": "^0.6.0",
"zeego": "^1.7.2",
"zod": "^3.22.2"
"zeego": "^1.7.2"
},
"devDependencies": {
"@babel/core": "^7.23.7",
Expand Down
3 changes: 1 addition & 2 deletions packages/app/atoms/progressStore/progressStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export const useProgressListener = () => {

useEffect(() => {
const handler = (evt) => dispatch(evt);
progressEvents.addListener('dispatch', handler);

progressEvents.once('dispatch', handler);
return () => {
progressEvents.removeListener('dispatch', handler);
};
Expand Down
4 changes: 3 additions & 1 deletion packages/app/components/feed/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export default function Card({
gap: 8,
}}
>
<Link href={`/profile/${owner?._id}`}>
<Link
href={`/profile/${type === 'pack' ? owner_id : owner?._id}`}
>
<RText color={currentTheme.colors.textColor}>
View {owner?.username ? '@' + owner?.username : 'Owner'}
</RText>
Expand Down
3 changes: 3 additions & 0 deletions packages/app/components/navigation/NavigationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const NavigationList = ({
style={ {
width: '100%',
borderRadius: 8,
marginBottom: isMobileView ? 25 : 0,
backgroundColor: currentTheme.colors.background,
color: currentTheme.colors.white
}}
hoverStyle={ {
bg: currentTheme.colors.secondaryBlue,
Expand Down
15 changes: 6 additions & 9 deletions packages/app/components/pack/AddPack.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { Platform, View } from 'react-native';
import {
RButton,
Expand All @@ -14,7 +15,7 @@ import useTheme from '../../hooks/useTheme';
import useCustomStyles from 'app/hooks/useCustomStyles';
import { useAddNewPack } from 'app/hooks/packs';
import { useRouter } from 'app/hooks/router';
import { z } from 'zod';
import { addPackSchema } from '@packrat/validations';

export const AddPack = ({ isCreatingTrip = false }) => {
// Hooks
Expand Down Expand Up @@ -78,7 +79,10 @@ export const AddPack = ({ isCreatingTrip = false }) => {
accessibilityLabel="Choose Service"
placeholder={'Is Public'}
/>
<SubmitButton style={{ width: '100%', marginTop: 40 }} onSubmit={handleAddPack}>
<SubmitButton
style={{ width: '100%', marginTop: 40 }}
onSubmit={handleAddPack}
>
<RText style={{ color: currentTheme.colors.text }}>
{isLoading ? 'Loading...' : 'Add Pack'}
</RText>
Expand Down Expand Up @@ -152,10 +156,3 @@ const loadStyles = (theme, appTheme) => {
},
};
};

// TODO move to validations workspace

export const addPackSchema = z.object({
name: z.string().nonempty(),
isPublic: z.union([z.literal('0'), z.literal('1')]),
});
2 changes: 1 addition & 1 deletion packages/app/components/pack/PackContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function PackContainer({ isCreatingTrip = false }) {
error,
isLoading,
refetch: refetchQuery,
} = useUserPacks((ownerId = user?._id));
} = useUserPacks(user?._id);

useEffect(() => {
refetchQuery();
Expand Down
4 changes: 1 addition & 3 deletions packages/app/components/password-reset/RequestEmailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export const RequestPasswordResetEmailModal = () => {

const [formRef, triggerSubmit] = useFormSubmitTrigger();

console.log(formRef);

return (
<BaseModal
title="Reset Password"
Expand All @@ -38,7 +36,7 @@ export const RequestPasswordResetEmailModal = () => {
]}
>
<Form
formRef={formRef}
ref={formRef}
onSubmit={handleResetPasswordEmail}
validationSchema={emailExists}
>
Expand Down
4 changes: 2 additions & 2 deletions packages/app/components/trip/createTripModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { DropdownComponent } from '../Dropdown';
import { useAuthUser } from 'app/auth/hooks';
import { addTripForm } from '@packrat/validations/src/validations/tripRoutesValidator';
import { useFormSubmitTrigger } from '@packrat/ui/src/form';
import { usePackId } from 'app/hooks/packs/usePackId';
import { usePackId } from 'app/hooks/packs';

interface SaveTripContainerProps {
dateRange: {
Expand Down Expand Up @@ -154,7 +154,7 @@ export const SaveTripContainer = ({
>
<Form
validationSchema={addTripForm}
formRef={formRef}
ref={formRef}
onSubmit={handleCreateTrip}
defaultValues={{ isPublic: '0' }}
>
Expand Down
6 changes: 4 additions & 2 deletions packages/app/context/FontLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {
SimpleLineIcons,
Zocial,
} from '@expo/vector-icons';
import Inter from '@tamagui/font-inter/otf/Inter-Medium.otf';
import InterBold from '@tamagui/font-inter/otf/Inter-Bold.otf';

const FontLoader = ({ children }) => {
const [loaded] = useFonts({
// Inter: require('@tamagui/font-inter/otf/Inter-Medium.otf'),
// InterBold: require('@tamagui/font-inter/otf/Inter-Bold.otf'),
Inter,
InterBold,
// Cache all icon fonts
...AntDesign.font,
...Entypo.font,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/hooks/common/useIsMobileView/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const useIsMobileView = () => {

const { screenWidth } = useScreenWidth();

return screenWidth < 1900; // hard coded for now, will be replaced with media queries
return screenWidth < 768; // hard coded for now, will be replaced with media queries
};
1 change: 0 additions & 1 deletion packages/app/hooks/packs/useEditPackItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { util } from 'zod';
import { queryTrpc } from '../../trpc';
import { useItemsUpdater } from 'app/hooks/items';
import { useOfflineQueue } from 'app/hooks/offline';
Expand Down
4 changes: 2 additions & 2 deletions packages/app/hooks/storage/useStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function useStorage(key: string): UseStateHook<string> {
setState(null);
};

storageEvents.addListener('change', handleChange);
storageEvents.addListener('remove', handleRemove);
storageEvents.once('change', handleChange);
storageEvents.once('remove', handleRemove);

return () => {
storageEvents.removeListener('change', handleChange);
Expand Down
3 changes: 1 addition & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@
"tamagui": "^1.91.3",
"togpx": "^0.5.4",
"uuid": "3.4.0",
"xmldom": "^0.6.0",
"zod": "^3.22.2"
"xmldom": "^0.6.0"
},
"devDependencies": {
"@babel/core": "^7.23.7",
Expand Down
18 changes: 5 additions & 13 deletions packages/app/screens/user/ProfileContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const Header = ({
<>
<RSkeleton
style={{
borderRadius: '100%',
borderRadius: 100,
height: 100,
width: 100,
}}
Expand Down Expand Up @@ -101,18 +101,10 @@ const Header = ({
<RStack style={{ flexDirection: 'row', ...styles.card }}>
{isLoading ? (
<>
<RSkeleton
style={{ borderRadius: '100%', width: 50, height: 50 }}
/>
<RSkeleton
style={{ borderRadius: '100%', width: 50, height: 50 }}
/>
<RSkeleton
style={{ borderRadius: '100%', width: 50, height: 50 }}
/>
<RSkeleton
style={{ borderRadius: '100%', width: 50, height: 50 }}
/>
<RSkeleton style={{ borderRadius: 100, width: 50, height: 50 }} />
<RSkeleton style={{ borderRadius: 100, width: 50, height: 50 }} />
<RSkeleton style={{ borderRadius: 100, width: 50, height: 50 }} />
<RSkeleton style={{ borderRadius: 100, width: 50, height: 50 }} />
</>
) : (
<>
Expand Down
44 changes: 9 additions & 35 deletions packages/app/screens/user/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
ImageUpload,
FormInput,
FormSelect,
SubmitButton,
} from '@packrat/ui';
import Avatar from 'app/components/Avatar/Avatar';
import { useProfileSettings } from 'app/hooks/user';
import { z } from 'zod';
import { userSettingsSchema, passwordChangeSchema } from '@packrat/validations';

const weatherOptions = ['celsius', 'fahrenheit'].map((key) => ({
label: key,
Expand Down Expand Up @@ -44,11 +45,7 @@ export default function Settings() {
<RH2>Profile</RH2>
<RSeparator marginVertical={8} />
</RStack>
<Form
onSubmit={handleEditUser}
validationSchema={userSettingsSchema}
defaultValues={{ ...user }}
>
<Form validationSchema={userSettingsSchema} defaultValues={{ ...user }}>
<RStack space="$3" width="fit-content" marginHorizontal="auto">
<ImageUpload
label="Profile Picture"
Expand Down Expand Up @@ -90,9 +87,13 @@ export default function Settings() {
</RStack>
</RStack>
</RStack>
<RButton color="white" style={{ backgroundColor: '#0284c7' }}>
<SubmitButton
onSubmit={handleEditUser}
color="white"
style={{ backgroundColor: '#0284c7' }}
>
Update profile
</RButton>
</SubmitButton>
</RStack>
</Form>

Expand Down Expand Up @@ -136,30 +137,3 @@ export default function Settings() {
</RScrollView>
) : null;
}

// TODO move to validations workspace

const userSettingsSchema = z.object({
name: z.string().min(1).nonempty(),
email: z.string().email().nonempty(),
username: z.string().nonempty(),
profileImage: z.string().optional(),
preferredWeather: z.union([z.literal('celsius'), z.literal('fahrenheit')]),
preferredWeight: z.union([
z.literal('lb'),
z.literal('oz'),
z.literal('kg'),
z.literal('g'),
]),
});

const passwordChangeSchema = z
.object({
oldPassword: z.string().min(1, 'Old password is required'),
newPassword: z.string().nonempty(),
confirmPassword: z.string().nonempty(),
})
.refine((data) => data.newPassword === data.confirmPassword, {
message: 'New password and confirmation must match',
path: ['confirmPassword'], // This will attach the error to `passwordConfirm` field
});
56 changes: 24 additions & 32 deletions packages/ui/src/form/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { type ReactNode } from 'react';
import { forwardRef, useImperativeHandle, type ReactNode } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import {
FieldValues,
Form as RHFForm,
FormProvider,
FormSubmitHandler,
UseFormProps,
useForm,
useFormContext,
} from 'react-hook-form';
import { Platform } from 'react-native';
export { useFormContext as useAppFormContext } from 'react-hook-form';

interface Props extends Omit<UseFormProps, 'resolver'> {
Expand All @@ -19,34 +16,29 @@ interface Props extends Omit<UseFormProps, 'resolver'> {
children: ReactNode;
}

// TODO change the name to "Form" after handling tamagui all components export,
// which is cause of a name collision
export const Form = ({
validationSchema,
onSubmit,
children,
formRef,
...formProps
}: Props) => {
const form = useForm({
...formProps,
resolver: validationSchema ? zodResolver(validationSchema) : undefined,
});
export const Form = forwardRef<any, Props>(
({ validationSchema, onSubmit, children, ...formProps }, ref) => {
const form = useForm({
...formProps,
resolver: validationSchema ? zodResolver(validationSchema) : undefined,
});

if (formRef && !formRef?.current && typeof onSubmit === 'function') {
formRef.current = {
submit: (...params) =>
form.handleSubmit(onSubmit.bind(null, ...params))(),
};
}
useImperativeHandle(
ref,
() => {
return {
submit: (...params) =>
typeof onSubmit === 'function' &&
form.handleSubmit(onSubmit.bind(null, ...params))(),
};
},
[form, onSubmit],
);

return (
<FormProvider {...form}>
{Platform.OS === 'web' ? (
<RHFForm onSubmit={form.handleSubmit(onSubmit)}>{children}</RHFForm>
) : (
return (
<FormProvider {...form}>
<>{children}</>
)}
</FormProvider>
);
};
</FormProvider>
);
},
);
2 changes: 1 addition & 1 deletion packages/ui/src/form/components/SubmitButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LmSubmitButtonRhf, type LmButtonRhfProps } from '../lib';

interface Props<T extends {}> extends LmButtonRhfProps<T> {
onSubmit: (values: T) => void;
onSubmit?: (values: T) => void;
}

export const SubmitButton = <T extends {}>({
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/form/useFormSubmitTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useRef } from 'react';

export const useFormSubmitTrigger = () => {
const formRef = useRef(null);
const formRef = useRef<{ submit: (...params: any) => void }>(null);

const triggerFormSubmit = (...params) => {
console.log(params);
formRef.current?.submit?.(...params);
};

Expand Down
5 changes: 5 additions & 0 deletions packages/validations/src/validations/packRoutesValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ export const getPublicPacks = z.object({
export const sendMessage = z.object({
message: z.string().nonempty(),
});

export const addPackSchema = z.object({
name: z.string().nonempty(),
isPublic: z.union([z.literal('0'), z.literal('1')]),
});
Loading

0 comments on commit 1ec7325

Please sign in to comment.