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

Trip review feature init #956

Open
wants to merge 1 commit into
base: andrew_testing
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mongodb-data
.env.production
.env.old
node_modules
local-files
# yarn.lock
# dist
old/
Expand Down
15 changes: 8 additions & 7 deletions packages/app/components/card/PackCardHeader/PackCardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EditableText,
RIconButton,
RStack,
ZDropdown,
} from '@packrat/ui';
import { useDeletePack, useFetchSinglePack } from 'app/hooks/packs';
import { usePackTitleInput } from './usePackTitleInput';
Expand Down Expand Up @@ -83,13 +84,13 @@ export const PackCardHeader = ({ data, title, link }: PackCardHeaderProps) => {
link={link}
actionsComponent={
user?.id === data.owner_id && (
<ThreeDotsMenu onOpenChange={handleActionsOpenChange}>
<YStack space="$1">
<RButton onPress={handleEdit}>Edit</RButton>
<RButton onPress={handleSavePack}>Save</RButton>
<RButton onPress={handleDeletePack}>Delete</RButton>
</YStack>
</ThreeDotsMenu>
<ZDropdown
dropdownItems={[
{label: 'Edit', onSelect: handleEdit },
{label: 'Save', onSelect: handleSavePack },
{label: 'Delete', onSelect: handleDeletePack },
]}
/>
)
}
/>
Expand Down
19 changes: 17 additions & 2 deletions packages/app/components/card/TripCardHeader/TripCardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { Platform, Text } from 'react-native';
import { useRouter } from 'app/hooks/router';
import useTheme from 'app/hooks/useTheme';
import { CustomCardHeader } from '../CustomCardHeader';
import { RIconButton, RStack } from '@packrat/ui';
import { RIconButton, RStack, ZDropdown } from '@packrat/ui';
import { AntDesign } from '@expo/vector-icons';
import { useAuthUser } from 'app/auth/hooks';
import { useCompleteTrip } from 'app/hooks/trips';
import { EditTripModal } from 'app/components/trip/EditTripModal';

export const TripCardHeader = ({ data, title, link }) => {
const { isDark, currentTheme } = useTheme();
const user = useAuthUser();
const completeTrip = useCompleteTrip();
const router = useRouter();

return (
Expand Down Expand Up @@ -44,7 +49,17 @@ export const TripCardHeader = ({ data, title, link }) => {
</RStack>
}
link={link}
actionsComponent={undefined}
actionsComponent={
user?.id === data.owner_id && (
<ZDropdown
dropdownItems={[
{label: <EditTripModal /> },
...(!data.is_completed ? [{label: 'Mark as complete', onSelect: () => {completeTrip(data.id)} }] : []),
{label: 'Delete', onSelect: () => {} },
]}
/>
)
}
/>
);
};
12 changes: 2 additions & 10 deletions packages/app/components/pack_table/TableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,14 @@ const TableItem = ({
];
}

let rowData = [
const rowData = [
<RText px={8}>{name}</RText>,
<RText px={8}>{`${formatNumber(weight)} ${unit}`}</RText>,
<RText px={8}>{quantity}</RText>,
];

if (hasPermissions) {
if (
Platform.OS === 'android' ||
Platform.OS === 'ios' ||
window.innerWidth < 900
) {
rowData.push(<ZDropdown.Native dropdownItems={rowActionItems} />);
} else {
rowData.push(<ZDropdown.Web dropdownItems={rowActionItems} />);
}
rowData.push(<ZDropdown dropdownItems={rowActionItems} />);
}

/*
Expand Down
22 changes: 22 additions & 0 deletions packages/app/components/trip/EditTripModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import useTheme from 'app/hooks/useTheme';
import { BaseModal, Form, FormInput, RStack, RText } from '@packrat/ui';

export const EditTripModal = () => {

return (
<BaseModal
title="Add Item"
trigger="Add Item"
footerButtons={[
{
label: 'Cancel',
color: '#B22222',
onClick: (_, closeModal) => closeModal(),
},
]}
footerComponent={undefined}
>
<RText>TripModal</RText>
</BaseModal>
);
};
1 change: 1 addition & 0 deletions packages/app/config/trpcAxiosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const REQUESTS_TO_SKIP_SUCCESS_MESSAGE = [
'getMe',
'signUp',
'signIn',
'completeTrip',
'resetPasswordEmail',
'resetPassword',
];
Expand Down
2 changes: 2 additions & 0 deletions packages/app/hooks/trips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export * from './useDeleteTrips';
export * from './useFetchTrips';
export * from './useEditTrips';
export * from './useTripId';
export * from './useCompleteTrip';
export * from './useTripImages';
24 changes: 24 additions & 0 deletions packages/app/hooks/trips/useCompleteTrip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { InformUser } from 'app/utils/ToastUtils';
import { queryTrpc } from '../../trpc';

export const useCompleteTrip = () => {
const utils = queryTrpc.useUtils();
const mutation = queryTrpc.completeTrip.useMutation();

const completeTrip = (tripId: string) => {
mutation.mutate({tripId}, {
onSuccess: (result) => {
utils.getTrips.invalidate();

InformUser({
title: 'Trip completed! Share your experience with others',
placement: 'bottom',
duration: 3000,
style: { backgroundColor: 'green' },
});
},
});
};

return completeTrip;
};
21 changes: 21 additions & 0 deletions packages/app/hooks/trips/useTripImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { queryTrpc } from '../../trpc';

export const useTripImages = () => {
const utils = queryTrpc.useUtils();
const { mutate: addTripImageMutation } = queryTrpc.addTripImage.useMutation();

const addTripImage = (tripId: string, image: string) => {
addTripImageMutation(
{ tripId, image },
{
onSuccess: () => {
utils.getTrips.invalidate();
},
},
);
};

return {
addTripImage,
};
};
10 changes: 10 additions & 0 deletions packages/app/screens/trip/TripDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
WeatherCardComponent,
TripCardComponent,
ScoreContainerComponent,
TripReview,
loadStyles,
} from './TripDetailsComponents';
import { useTripId } from 'app/hooks/trips';
Expand All @@ -27,6 +28,7 @@ const SECTION = {
TABLE: 'TABLE',
WEATHER: 'WEATHER',
TRIP: 'TRIP',
REVIEW: 'REVIEW',
SCORE: 'SCORE',
};

Expand Down Expand Up @@ -142,6 +144,14 @@ export function TripDetails() {
currentTheme={currentTheme}
/>
);
case SECTION.REVIEW:
return (
<TripReview
data={data}
weatherObject={weatherObject}
currentTheme={currentTheme}
/>
);
case SECTION.SCORE:
return (
<ScoreContainer
Expand Down
40 changes: 37 additions & 3 deletions packages/app/screens/trip/TripDetailsComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ import { FontAwesome5 } from '@expo/vector-icons';
import { theme } from '../../theme';
import { TripMapCard } from 'app/components/trip/TripCards';
import { useFetchSinglePack } from 'app/hooks/packs';
import { RSkeleton, RText } from '@packrat/ui';
import {
Form,
RSkeleton,
RStack,
RText,
SubmitButton,
FormInput,
BImagePicker,
} from '@packrat/ui';
import useTheme from '../../hooks/useTheme';
import { useTripImages } from 'app/hooks/trips';

const TableContainerComponent = ({ currentPack }) => {
const { data, isLoading } = useFetchSinglePack(currentPack.id || currentPack);
Expand All @@ -35,22 +44,46 @@ const WeatherCardComponent = ({ weatherObject, weatherWeek, data }) => (
);

const TripCardComponent = ({ data, weatherObject, currentTheme }) =>
data?.geojson?.features?.length && (
data?.geojson?.features?.length ? (
// data?.geojson && (
<TripMapCard
shape={data.geojson}
// cords={
// data?.weather ? JSON?.parse(data?.weather)?.coord : weatherObject?.coord
// }
/>
);
) : null;

const ScoreContainerComponent = ({ data, isOwner }) => (
<View style={{ marginTop: '5%' }}>
<ScoreContainer type="trip" data={data} isOwner={isOwner} />
</View>
);

const TripReview = ({ data }) => {
const { addTripImage } = useTripImages();
return data.is_completed ? (
<Form>
<RStack style={{ marginTop: 16, gap: 8, padding: 18 }}>
<RStack>
<BImagePicker
onChange={(images) => addTripImage(data.id, images[0])}
/>
</RStack>
<FormInput
name="message"
placeholder="Type a message..."
multiline
value={''}
/>
<SubmitButton>
<RText>Send</RText>
</SubmitButton>
</RStack>
</Form>
) : null;
};

const loadStyles = (theme) => {
const { isDark, currentTheme } = theme;
return {
Expand Down Expand Up @@ -83,5 +116,6 @@ export {
WeatherCardComponent,
TripCardComponent,
ScoreContainerComponent,
TripReview,
loadStyles,
};
2 changes: 1 addition & 1 deletion packages/config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { viteSource } from './sources/vite';

// Simplifying environment variable access using logical OR
const API_URL =
viteSource.VITE_PUBLIC_API_URL ||
import.meta.env.VITE_PUBLIC_API_URL ||
process.env.NEXT_PUBLIC_API_URL ||
process.env.EXPO_PUBLIC_API_URL;
const WEB_CLIENT_ID =
Expand Down
4 changes: 1 addition & 3 deletions packages/crosspath/types/lib-interface.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { LinkComponent, Router, CreateParam } from './model';
export declare function Link(
props: Parameters<LinkComponent>,
): ReturnType<LinkComponent>;
export declare function Link(props: Parameters<LinkComponent>): ReturnType<LinkComponent>;
export declare const createParam: CreateParam;
export declare function useRouter(): Router;
41 changes: 18 additions & 23 deletions packages/crosspath/types/model/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import { FC } from 'react';
import { LinkProps } from 'solito/link';
export interface CreateParamOptions {
initial?: string;
parse?: (param: string) => unknown;
stringify?: (param: unknown) => string;
initial?: string;
parse?: (param: string) => unknown;
stringify?: (param: unknown) => string;
}
export interface Router {
push: (url: URL) => void;
replace: (url: URL) => void;
back: () => void;
push: (url: URL) => void;
replace: (url: URL) => void;
back: () => void;
}
export type LinkComponent = FC<LinkProps>;
export type URL =
| string
| {
pathname?: string;
query?: Record<string, any>;
state?: Record<string, any>;
hash?: string;
as?: string | object;
};
export type URL = string | {
pathname?: string;
query?: Record<string, any>;
state?: Record<string, any>;
hash?: string;
as?: string | object;
};
export type CreateParam = <T>() => {
useParam: (
key: keyof T,
options?: CreateParamOptions,
) => [value: any, setValue: (value: any) => void];
useParams: (key: keyof T) => {
params: T;
setParams: (value: any) => void;
};
useParam: (key: keyof T, options?: CreateParamOptions) => [value: any, setValue: (value: any) => void];
useParams: (key: keyof T) => {
params: T;
setParams: (value: any) => void;
};
};
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"expo-image-picker": "^14.7.1",
"jotai": "^2.6.4",
"react": "18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.50.1",
"tamagui": "1.96.0",
"zeego": "^1.7.2"
Expand Down
Loading
Loading