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

[ZMA-1026] Update name & avatar permission request flow (Policy 6.1) #5

Merged
merged 1 commit into from
Nov 27, 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
6 changes: 1 addition & 5 deletions src/pages/cart/delivery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ export const Delivery: FC = () => {
},
{
left: <Icon icon="zi-user" className="my-auto" />,
right: (
<Suspense fallback={<RequestPersonPickerPhone />}>
<PersonPicker />
</Suspense>
),
right: <RequestPersonPickerPhone />,
},
{
left: <Icon icon="zi-note" className="my-auto" />,
Expand Down
27 changes: 20 additions & 7 deletions src/pages/cart/person-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { ListItem } from "components/list-item";
import React, { FC } from "react";
import { useRecoilValue, useSetRecoilState } from "recoil";
import {
useRecoilValue,
useRecoilValueLoadable,
useSetRecoilState,
} from "recoil";
import { phoneState, requestPhoneTriesState, userState } from "state";

export const PersonPicker: FC = () => {
const user = useRecoilValue(userState);
const user = useRecoilValueLoadable(userState);
const phone = useRecoilValue(phoneState);

if (!phone) {
return <RequestPersonPickerPhone />;
}

return <ListItem title={`${user.name} - ${phone}`} subtitle="Người nhận" />;
return (
<ListItem
title={
user.state === "hasValue" ? `${user.contents.name} - ${phone}` : phone
}
subtitle="Người nhận"
/>
);
};

export const RequestPersonPickerPhone: FC = () => {
const retry = useSetRecoilState(requestPhoneTriesState);
const phone = useRecoilValueLoadable(phoneState);

if (phone.state === "hasValue" && phone.contents) {
return <PersonPicker />;
}

return (
<ListItem
onClick={() => retry((r) => r + 1)}
Expand Down
11 changes: 0 additions & 11 deletions src/pages/index/welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import React, { FC } from "react";
import { Box, Header, Text } from "zmp-ui";
import { useRecoilValueLoadable } from "recoil";
import { userState } from "state";
import logo from "static/logo.png";
import appConfig from "../../../app-config.json";
import { getConfig } from "utils/config";

export const Welcome: FC = () => {
const user = useRecoilValueLoadable(userState);

return (
<Header
className="app-header no-border pl-4 flex-none pb-[6px]"
Expand All @@ -22,13 +18,6 @@ export const Welcome: FC = () => {
/>
<Box>
<Text.Title size="small">{appConfig.app.title}</Text.Title>
{user.state === "hasValue" ? (
<Text size="xxSmall" className="text-gray">
Welcome, {user.contents.name}!
</Text>
) : (
<Text>...</Text>
)}
</Box>
</Box>
) as unknown as string
Expand Down
16 changes: 14 additions & 2 deletions src/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import { Box, Header, Icon, Page, Text } from "zmp-ui";
import subscriptionDecor from "static/subscription-decor.svg";
import { ListRenderer } from "components/list-renderer";
import { useToBeImplemented } from "hooks";
import { useRecoilCallback } from "recoil";
import { userState } from "state";

const Subscription: FC = () => {
const onClick = useToBeImplemented();
const requestUserInfo = useRecoilCallback(
({ snapshot }) =>
async () => {
const userInfo = await snapshot.getPromise(userState);
console.warn("Các bên tích hợp có thể sử dụng userInfo ở đây...", {
userInfo,
});
},
[]
);

return (
<Box className="m-4" onClick={onClick}>
<Box className="m-4" onClick={requestUserInfo}>
<Box
className="bg-green text-white rounded-xl p-4 space-y-2"
style={{
Expand Down
12 changes: 2 additions & 10 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ import categories from "../mock/categories.json";
export const userState = selector({
key: "user",
get: async () => {
try {
const { userInfo } = await getUserInfo({ autoRequestPermission: true });
return userInfo;
} catch (error) {
return {
id: "",
avatar: "",
name: "Người dùng Zalo",
};
}
const { userInfo } = await getUserInfo({ autoRequestPermission: true });
return userInfo;
},
});

Expand Down
Loading