enh
This commit is contained in:
parent
f80f234b98
commit
9b38a3678b
10 changed files with 3718 additions and 5 deletions
|
|
@ -4,16 +4,19 @@ import { useRouter } from 'expo-router';
|
||||||
import { AppContainer, MyText, tw } from 'common-ui';
|
import { AppContainer, MyText, tw } from 'common-ui';
|
||||||
import TagForm from '@/src/components/TagForm';
|
import TagForm from '@/src/components/TagForm';
|
||||||
import { useCreateTag } from '@/src/api-hooks/tag.api';
|
import { useCreateTag } from '@/src/api-hooks/tag.api';
|
||||||
|
import { trpc } from '@/src/trpc-client';
|
||||||
|
|
||||||
interface TagFormData {
|
interface TagFormData {
|
||||||
tagName: string;
|
tagName: string;
|
||||||
tagDescription: string;
|
tagDescription: string;
|
||||||
isDashboardTag: boolean;
|
isDashboardTag: boolean;
|
||||||
|
relatedStores: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AddTag() {
|
export default function AddTag() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutate: createTag, isPending: isCreating } = useCreateTag();
|
const { mutate: createTag, isPending: isCreating } = useCreateTag();
|
||||||
|
const { data: storesData } = trpc.admin.store.getStores.useQuery();
|
||||||
|
|
||||||
const handleSubmit = (values: TagFormData, image?: { uri?: string }) => {
|
const handleSubmit = (values: TagFormData, image?: { uri?: string }) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
@ -25,6 +28,9 @@ export default function AddTag() {
|
||||||
}
|
}
|
||||||
formData.append('isDashboardTag', values.isDashboardTag.toString());
|
formData.append('isDashboardTag', values.isDashboardTag.toString());
|
||||||
|
|
||||||
|
// Add related stores
|
||||||
|
formData.append('relatedStores', JSON.stringify(values.relatedStores));
|
||||||
|
|
||||||
// Add image if uploaded
|
// Add image if uploaded
|
||||||
if (image?.uri) {
|
if (image?.uri) {
|
||||||
const filename = image.uri.split('/').pop() || 'image.jpg';
|
const filename = image.uri.split('/').pop() || 'image.jpg';
|
||||||
|
|
@ -58,6 +64,7 @@ export default function AddTag() {
|
||||||
tagName: '',
|
tagName: '',
|
||||||
tagDescription: '',
|
tagDescription: '',
|
||||||
isDashboardTag: false,
|
isDashboardTag: false,
|
||||||
|
relatedStores: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -70,6 +77,7 @@ export default function AddTag() {
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
isLoading={isCreating}
|
isLoading={isCreating}
|
||||||
|
stores={storesData?.stores.map(store => ({ id: store.id, name: store.name })) || []}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</AppContainer>
|
</AppContainer>
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ import { useRouter, useLocalSearchParams } from 'expo-router';
|
||||||
import { AppContainer, MyText, tw } from 'common-ui';
|
import { AppContainer, MyText, tw } from 'common-ui';
|
||||||
import TagForm from '@/src/components/TagForm';
|
import TagForm from '@/src/components/TagForm';
|
||||||
import { useGetTag, useUpdateTag } from '@/src/api-hooks/tag.api';
|
import { useGetTag, useUpdateTag } from '@/src/api-hooks/tag.api';
|
||||||
|
import { trpc } from '@/src/trpc-client';
|
||||||
|
|
||||||
interface TagFormData {
|
interface TagFormData {
|
||||||
tagName: string;
|
tagName: string;
|
||||||
tagDescription: string;
|
tagDescription: string;
|
||||||
isDashboardTag: boolean;
|
isDashboardTag: boolean;
|
||||||
|
relatedStores: number[];
|
||||||
existingImageUrl?: string;
|
existingImageUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,6 +21,7 @@ export default function EditTag() {
|
||||||
|
|
||||||
const { data: tagData, isLoading: isLoadingTag, error: tagError } = useGetTag(tagIdNum!);
|
const { data: tagData, isLoading: isLoadingTag, error: tagError } = useGetTag(tagIdNum!);
|
||||||
const { mutate: updateTag, isPending: isUpdating } = useUpdateTag();
|
const { mutate: updateTag, isPending: isUpdating } = useUpdateTag();
|
||||||
|
const { data: storesData } = trpc.admin.store.getStores.useQuery();
|
||||||
|
|
||||||
const handleSubmit = (values: TagFormData, image?: { uri?: string }) => {
|
const handleSubmit = (values: TagFormData, image?: { uri?: string }) => {
|
||||||
if (!tagIdNum) return;
|
if (!tagIdNum) return;
|
||||||
|
|
@ -32,6 +35,9 @@ export default function EditTag() {
|
||||||
}
|
}
|
||||||
formData.append('isDashboardTag', values.isDashboardTag.toString());
|
formData.append('isDashboardTag', values.isDashboardTag.toString());
|
||||||
|
|
||||||
|
// Add related stores
|
||||||
|
formData.append('relatedStores', JSON.stringify(values.relatedStores));
|
||||||
|
|
||||||
// Add image if uploaded
|
// Add image if uploaded
|
||||||
if (image?.uri) {
|
if (image?.uri) {
|
||||||
const filename = image.uri.split('/').pop() || 'image.jpg';
|
const filename = image.uri.split('/').pop() || 'image.jpg';
|
||||||
|
|
@ -86,6 +92,7 @@ export default function EditTag() {
|
||||||
tagName: tag.tagName,
|
tagName: tag.tagName,
|
||||||
tagDescription: tag.tagDescription || '',
|
tagDescription: tag.tagDescription || '',
|
||||||
isDashboardTag: tag.isDashboardTag,
|
isDashboardTag: tag.isDashboardTag,
|
||||||
|
relatedStores: tag.relatedStores || [],
|
||||||
existingImageUrl: tag.imageUrl || undefined,
|
existingImageUrl: tag.imageUrl || undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -100,6 +107,7 @@ export default function EditTag() {
|
||||||
existingImageUrl={tag.imageUrl || undefined}
|
existingImageUrl={tag.imageUrl || undefined}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
isLoading={isUpdating}
|
isLoading={isUpdating}
|
||||||
|
stores={storesData?.stores.map(store => ({ id: store.id, name: store.name })) || []}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</AppContainer>
|
</AppContainer>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export interface CreateTagPayload {
|
||||||
tagDescription?: string;
|
tagDescription?: string;
|
||||||
imageUrl?: string;
|
imageUrl?: string;
|
||||||
isDashboardTag: boolean;
|
isDashboardTag: boolean;
|
||||||
|
relatedStores?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateTagPayload {
|
export interface UpdateTagPayload {
|
||||||
|
|
@ -14,6 +15,7 @@ export interface UpdateTagPayload {
|
||||||
tagDescription?: string;
|
tagDescription?: string;
|
||||||
imageUrl?: string;
|
imageUrl?: string;
|
||||||
isDashboardTag: boolean;
|
isDashboardTag: boolean;
|
||||||
|
relatedStores?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tag {
|
export interface Tag {
|
||||||
|
|
@ -22,6 +24,7 @@ export interface Tag {
|
||||||
tagDescription: string | null;
|
tagDescription: string | null;
|
||||||
imageUrl: string | null;
|
imageUrl: string | null;
|
||||||
isDashboardTag: boolean;
|
isDashboardTag: boolean;
|
||||||
|
relatedStores: number[];
|
||||||
createdAt?: string;
|
createdAt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,20 @@ import { View, TouchableOpacity } from 'react-native';
|
||||||
import { Image } from 'expo-image';
|
import { Image } from 'expo-image';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { MyTextInput, MyText, Checkbox, ImageUploader, tw, useFocusCallback } from 'common-ui';
|
import { MyTextInput, MyText, Checkbox, ImageUploader, tw, useFocusCallback, BottomDropdown } from 'common-ui';
|
||||||
import usePickImage from 'common-ui/src/components/use-pick-image';
|
import usePickImage from 'common-ui/src/components/use-pick-image';
|
||||||
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
|
||||||
|
|
||||||
|
interface StoreOption {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface TagFormData {
|
interface TagFormData {
|
||||||
tagName: string;
|
tagName: string;
|
||||||
tagDescription: string;
|
tagDescription: string;
|
||||||
isDashboardTag: boolean;
|
isDashboardTag: boolean;
|
||||||
|
relatedStores: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TagFormProps {
|
interface TagFormProps {
|
||||||
|
|
@ -19,6 +25,7 @@ interface TagFormProps {
|
||||||
existingImageUrl?: string;
|
existingImageUrl?: string;
|
||||||
onSubmit: (values: TagFormData, image?: { uri?: string }) => void;
|
onSubmit: (values: TagFormData, image?: { uri?: string }) => void;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
stores?: StoreOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const TagForm = forwardRef<any, TagFormProps>(({
|
const TagForm = forwardRef<any, TagFormProps>(({
|
||||||
|
|
@ -27,6 +34,7 @@ const TagForm = forwardRef<any, TagFormProps>(({
|
||||||
existingImageUrl = '',
|
existingImageUrl = '',
|
||||||
onSubmit,
|
onSubmit,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
stores = [],
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const [image, setImage] = useState<{ uri?: string } | null>(null);
|
const [image, setImage] = useState<{ uri?: string } | null>(null);
|
||||||
const [isDashboardTagChecked, setIsDashboardTagChecked] = useState<boolean>(Boolean(initialValues.isDashboardTag));
|
const [isDashboardTagChecked, setIsDashboardTagChecked] = useState<boolean>(Boolean(initialValues.isDashboardTag));
|
||||||
|
|
@ -120,6 +128,27 @@ const TagForm = forwardRef<any, TagFormProps>(({
|
||||||
<MyText style={tw`ml-3 text-gray-800`}>Mark as Dashboard Tag</MyText>
|
<MyText style={tw`ml-3 text-gray-800`}>Mark as Dashboard Tag</MyText>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* Related Stores Dropdown */}
|
||||||
|
<View style={tw`mb-6`}>
|
||||||
|
<MyText style={tw`text-lg font-bold mb-2 text-gray-800`}>
|
||||||
|
Related Stores
|
||||||
|
</MyText>
|
||||||
|
<BottomDropdown
|
||||||
|
label="Select Related Stores"
|
||||||
|
placeholder="Select stores..."
|
||||||
|
value={values.relatedStores.map(id => id.toString())}
|
||||||
|
options={stores.map(store => ({
|
||||||
|
label: store.name,
|
||||||
|
value: store.id.toString(),
|
||||||
|
}))}
|
||||||
|
onValueChange={(selectedValues) => {
|
||||||
|
const numericValues = (selectedValues as string[]).map(v => parseInt(v));
|
||||||
|
formikSetFieldValue('relatedStores', numericValues);
|
||||||
|
}}
|
||||||
|
multiple={true}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => handleSubmit()}
|
onPress={() => handleSubmit()}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
|
|
|
||||||
1
apps/backend/drizzle/0071_moaning_shadow_king.sql
Normal file
1
apps/backend/drizzle/0071_moaning_shadow_king.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE "mf"."product_tag_info" ADD COLUMN "related_stores" jsonb;
|
||||||
3630
apps/backend/drizzle/meta/0071_snapshot.json
Normal file
3630
apps/backend/drizzle/meta/0071_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -498,6 +498,13 @@
|
||||||
"when": 1769958949864,
|
"when": 1769958949864,
|
||||||
"tag": "0070_known_ares",
|
"tag": "0070_known_ares",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 71,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1770321591876,
|
||||||
|
"tag": "0071_moaning_shadow_king",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ import { deleteS3Image } from "../lib/delete-image";
|
||||||
* Create a new product tag
|
* Create a new product tag
|
||||||
*/
|
*/
|
||||||
export const createTag = async (req: Request, res: Response) => {
|
export const createTag = async (req: Request, res: Response) => {
|
||||||
const { tagName, tagDescription, isDashboardTag } = req.body;
|
const { tagName, tagDescription, isDashboardTag, relatedStores } = req.body;
|
||||||
|
|
||||||
if (!tagName) {
|
if (!tagName) {
|
||||||
throw new ApiError("Tag name is required", 400);
|
throw new ApiError("Tag name is required", 400);
|
||||||
|
|
@ -33,6 +33,18 @@ export const createTag = async (req: Request, res: Response) => {
|
||||||
imageUrl = await imageUploadS3(req.file.buffer, req.file.mimetype, key);
|
imageUrl = await imageUploadS3(req.file.buffer, req.file.mimetype, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse relatedStores if it's a string (from FormData)
|
||||||
|
let parsedRelatedStores: number[] = [];
|
||||||
|
if (relatedStores) {
|
||||||
|
try {
|
||||||
|
parsedRelatedStores = typeof relatedStores === 'string'
|
||||||
|
? JSON.parse(relatedStores)
|
||||||
|
: relatedStores;
|
||||||
|
} catch (e) {
|
||||||
|
parsedRelatedStores = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [newTag] = await db
|
const [newTag] = await db
|
||||||
.insert(productTagInfo)
|
.insert(productTagInfo)
|
||||||
.values({
|
.values({
|
||||||
|
|
@ -40,6 +52,7 @@ export const createTag = async (req: Request, res: Response) => {
|
||||||
tagDescription,
|
tagDescription,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
isDashboardTag: isDashboardTag || false,
|
isDashboardTag: isDashboardTag || false,
|
||||||
|
relatedStores: parsedRelatedStores,
|
||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
|
@ -103,7 +116,7 @@ export const getTagById = async (req: Request, res: Response) => {
|
||||||
*/
|
*/
|
||||||
export const updateTag = async (req: Request, res: Response) => {
|
export const updateTag = async (req: Request, res: Response) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
const { tagName, tagDescription, isDashboardTag } = req.body;
|
const { tagName, tagDescription, isDashboardTag, relatedStores } = req.body;
|
||||||
|
|
||||||
// Get the current tag to check for existing image
|
// Get the current tag to check for existing image
|
||||||
const currentTag = await db.query.productTagInfo.findFirst({
|
const currentTag = await db.query.productTagInfo.findFirst({
|
||||||
|
|
@ -135,6 +148,18 @@ export const updateTag = async (req: Request, res: Response) => {
|
||||||
imageUrl = await imageUploadS3(req.file.buffer, req.file.mimetype, key);
|
imageUrl = await imageUploadS3(req.file.buffer, req.file.mimetype, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse relatedStores if it's a string (from FormData)
|
||||||
|
let parsedRelatedStores: number[] | undefined;
|
||||||
|
if (relatedStores !== undefined) {
|
||||||
|
try {
|
||||||
|
parsedRelatedStores = typeof relatedStores === 'string'
|
||||||
|
? JSON.parse(relatedStores)
|
||||||
|
: relatedStores;
|
||||||
|
} catch (e) {
|
||||||
|
parsedRelatedStores = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [updatedTag] = await db
|
const [updatedTag] = await db
|
||||||
.update(productTagInfo)
|
.update(productTagInfo)
|
||||||
.set({
|
.set({
|
||||||
|
|
@ -142,6 +167,7 @@ export const updateTag = async (req: Request, res: Response) => {
|
||||||
tagDescription,
|
tagDescription,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
isDashboardTag,
|
isDashboardTag,
|
||||||
|
relatedStores: parsedRelatedStores,
|
||||||
})
|
})
|
||||||
.where(eq(productTagInfo.id, parseInt(id)))
|
.where(eq(productTagInfo.id, parseInt(id)))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ export const productTagInfo = mf.table('product_tag_info', {
|
||||||
tagDescription: varchar('tag_description', { length: 500 }),
|
tagDescription: varchar('tag_description', { length: 500 }),
|
||||||
imageUrl: varchar('image_url', { length: 500 }),
|
imageUrl: varchar('image_url', { length: 500 }),
|
||||||
isDashboardTag: boolean('is_dashboard_tag').notNull().default(false),
|
isDashboardTag: boolean('is_dashboard_tag').notNull().default(false),
|
||||||
|
relatedStores: jsonb('related_stores').$defaultFn(() => []),
|
||||||
createdAt: timestamp('created_at').notNull().defaultNow(),
|
createdAt: timestamp('created_at').notNull().defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,8 @@ const isDevMode = Constants.executionEnvironment !== "standalone";
|
||||||
// const BASE_API_URL = 'http://10.0.2.2:4000';
|
// const BASE_API_URL = 'http://10.0.2.2:4000';
|
||||||
// const BASE_API_URL = 'http://192.168.100.101:4000';
|
// const BASE_API_URL = 'http://192.168.100.101:4000';
|
||||||
// const BASE_API_URL = 'http://192.168.1.7:4000';
|
// const BASE_API_URL = 'http://192.168.1.7:4000';
|
||||||
let BASE_API_URL = "https://mf.freshyo.in";
|
// let BASE_API_URL = "https://mf.freshyo.in";
|
||||||
// let BASE_API_URL = 'http://192.168.100.104:4000';
|
let BASE_API_URL = 'http://192.168.100.104:4000';
|
||||||
// let BASE_API_URL = 'http://192.168.29.176:4000';
|
// let BASE_API_URL = 'http://192.168.29.176:4000';
|
||||||
|
|
||||||
// if(isDevMode) {
|
// if(isDevMode) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue