Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6a257db
refactor: replace deprecated Apollo onCompleted/onError callbacks wit…
akanshaaa19 Mar 17, 2026
750725f
refactor: update mutation handling to use async/await for better erro…
akanshaaa19 Mar 17, 2026
784ce37
Merge branch 'master' into apollo_v4/batch_1
akanshaaa19 Mar 18, 2026
29851a6
refactor: remove deprecated tier state and update to use qualityRatin…
akanshaaa19 Mar 18, 2026
9b5cc51
refactor: enhance error handling and notifications in Flow, HSMList, …
akanshaaa19 Mar 18, 2026
8c98323
refactor: improve error handling in FormLayout; update notification m…
akanshaaa19 Mar 18, 2026
eddb8a7
refactor: update notification message handling in FormLayout; rename …
akanshaaa19 Mar 18, 2026
f55d9fd
refactor: enhance loading state handling in FormLayout; clean up HSML…
akanshaaa19 Mar 18, 2026
98d1d6f
refactor: improve loading state handling in FormLayout; remove unused…
akanshaaa19 Mar 18, 2026
1723d58
refactor: streamline FormLayout logic; remove redundant variable decl…
akanshaaa19 Mar 18, 2026
1d0c1c6
refactor: enhance FlowList tests; add error handling for import, expo…
akanshaaa19 Mar 18, 2026
b5c2003
refactor: enhance saveHandler and related functions to support isSave…
akanshaaa19 Mar 23, 2026
d958b49
Merge branch 'master' of github.com:glific/glific-frontend into apoll…
akanshaaa19 Mar 23, 2026
61b304f
chore: update cypress testing workflow to checkout apollo_migration b…
akanshaaa19 Mar 23, 2026
970defa
refactor: extract languageId logic into a separate function for impro…
akanshaaa19 Mar 23, 2026
bd72a64
Merge branch 'master' into apollo_v4/batch_1
akanshaaa19 Mar 26, 2026
4709abd
Merge branch 'master' of github.com:glific/glific-frontend into apoll…
akanshaaa19 Apr 6, 2026
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
8 changes: 3 additions & 5 deletions src/components/UI/Layout/Navigation/SideMenus/SideMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,17 @@ const SideMenus = ({ opened }: SideMenusProps) => {
const { t } = useTranslation();

// handle count for notifictions
const [notificationCount, setNotificationCount] = useState(0);
const [getNotificationCount] = useLazyQuery(GET_NOTIFICATIONS_COUNT, {
const [getNotificationCount, { data: notificationData }] = useLazyQuery(GET_NOTIFICATIONS_COUNT, {
variables: {
filter: {
is_read: false,
},
},
fetchPolicy: 'cache-and-network',
onCompleted: (countData) => {
setNotificationCount(countData.countNotifications);
},
});

const notificationCount = notificationData?.countNotifications ?? 0;

useEffect(() => {
getNotificationCount();
}, []);
Expand Down
82 changes: 31 additions & 51 deletions src/containers/Flow/FlowList/FlowList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const FlowList = () => {
const { t } = useTranslation();
const [filter, setFilter] = useState<any>(true);
const [selectedtag, setSelectedTag] = useState<any>(null);
const [flowName, setFlowName] = useState('');
const [importing, setImporting] = useState(false);
const [importStatus, setImportStatus] = useState([]);
const [showDialog, setShowDialog] = useState(false);
Expand All @@ -89,28 +88,10 @@ export const FlowList = () => {
releaseFlow();
}, []);

const [importFlow] = useMutation(IMPORT_FLOW, {
onCompleted: (result: any) => {
const { status } = result.importFlow;
setImportStatus(status);
setImporting(false);
},
onError: (error: any) => {
setNotification('An error occured while importing the flow', 'warning');
setImporting(false);
},
});
const [importFlow] = useMutation(IMPORT_FLOW);

const [exportFlowMutation] = useLazyQuery(EXPORT_FLOW, {
fetchPolicy: 'network-only',
onCompleted: async ({ exportFlow }) => {
const { exportData } = exportFlow;
await exportFlowMethod(exportData, flowName);
setNotification('Flow exported successfully');
},
onError: (error: any) => {
setErrorMessage(error);
},
});

const [updatePinned] = useMutation(PIN_FLOW);
Expand All @@ -123,41 +104,40 @@ export const FlowList = () => {
navigate(`/flow/${id}/edit`, { state: 'copy' });
};

const exportFlow = (id: any, item: any) => {
setFlowName(item.name);
exportFlowMutation({ variables: { id } });
const exportFlow = async (id: any, item: any) => {
try {
const result = await exportFlowMutation({ variables: { id } });
const { exportData } = result.data.exportFlow;
await exportFlowMethod(exportData, item.name);
setNotification('Flow exported successfully');
} catch (error: any) {
setErrorMessage(error);
}
};

const handlePin = (updateFlowId: any, pin: boolean = false) => {
if (pin) {
updatePinned({
variables: {
updateFlowId,
input: {
isPinned: true,
},
},
onCompleted: () => {
setRefreshList(!refreshList);
setNotification('Flow pinned successfully');
},
});
} else {
updatePinned({
variables: {
updateFlowId,
input: {
isPinned: false,
},
},
onCompleted: () => {
setRefreshList(!refreshList);
setNotification('Flow unpinned successfully');
},
});
const handleImport = async (result: string) => {
try {
const { data } = await importFlow({ variables: { flow: result } });
const { status } = data.importFlow;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure status will always be there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yess

setImportStatus(status);
} catch {
setNotification('An error occured while importing the flow', 'warning');
} finally {
setImporting(false);
}
};

const handlePin = async (updateFlowId: any, pin: boolean = false) => {
await updatePinned({
variables: {
updateFlowId,
input: { isPinned: pin },
},
});
setRefreshList(!refreshList);
setNotification(pin ? 'Flow pinned successfully' : 'Flow unpinned successfully');
};

let dialog;

const displayPinned = (isPinned: boolean, id: any) => {
Expand Down Expand Up @@ -250,7 +230,7 @@ export const FlowList = () => {
<ImportButton
title={t('Import flow')}
onImport={() => setImporting(true)}
afterImport={(result: string) => importFlow({ variables: { flow: result } })}
afterImport={handleImport}
/>
);

Expand Down
90 changes: 44 additions & 46 deletions src/containers/Form/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ export const FormLayout = ({
}: FormLayoutProps) => {
const [showDialog, setShowDialog] = useState(false);
const [formSubmitted, setFormSubmitted] = useState(false);
const [languageId, setLanguageId] = useState('');
const [formCancelled, setFormCancelled] = useState(false);
const [action, setAction] = useState(false);
const [link, setLink] = useState(undefined);
const [deleted, setDeleted] = useState(false);
const [saveClick, onSaveClick] = useState(false);
const [isLoadedData, setIsLoadedData] = useState(false);
const [customError, setCustomError] = useState<any>(null);
const [showConfirmationDialog, setShowConfirmationDialog] = useState(false);
const params = useParams();
Expand Down Expand Up @@ -251,6 +249,50 @@ export const FormLayout = ({
}
};

const capitalListItemName = listItemName[0].toUpperCase() + listItemName.slice(1);

let itemId = entityId;
if (!itemId) {
itemId = params.id;
}

let variables: any = itemId ? { [idType]: itemId } : false;
if (listItem === 'credential') {
variables = params.type ? { shortcode: params.type } : false;
}

const organization = useQuery(USER_LANGUAGES, {
skip: !languageSupport,
});

const { loading, error, data: itemData, refetch } = useQuery(getItemQuery, {
variables,
skip: !itemId,
fetchPolicy: getQueryFetchPolicy,
onCompleted: (data) => {
if (data) {
const loadedItem = data[listItem]?.[listItem] ?? data[Object.keys(data)[0]]?.[listItem];
if (loadedItem && setStates) {
setStates(loadedItem);
}
}
},
});

const fetchedItem: any = itemData
? (itemData[listItem]?.[listItem] ?? itemData[Object.keys(itemData)[0]]?.[listItem] ?? null)
: null;

const isLoadedData = Boolean(fetchedItem);

const languageId = fetchedItem
? languageSupport
? fetchedItem.language.id
: null
: !itemId && organization.data
? organization.data.currentUser.user.organization.defaultLanguage.id
: '';

const formik = useFormik({
initialValues: {
languageId,
Expand Down Expand Up @@ -284,16 +326,6 @@ export const FormLayout = ({
}
}, [entityId]);

const capitalListItemName = listItemName[0].toUpperCase() + listItemName.slice(1);
let item: any = null;

let itemId = entityId;
if (!itemId) {
itemId = params.id;
}

let variables: any = itemId ? { [idType]: itemId } : false;

const [deleteItem] = useMutation(deleteItemQuery, {
onCompleted: () => {
setNotification(`${capitalListItemName} deleted successfully`);
Expand All @@ -312,39 +344,6 @@ export const FormLayout = ({
],
});

// get the organization for current user and have languages option set to that.

const organization = useQuery(USER_LANGUAGES, {
skip: !languageSupport,
onCompleted: (data: any) => {
if (!itemId) {
setLanguageId(data.currentUser.user.organization.defaultLanguage.id);
}
},
});
if (listItem === 'credential') {
variables = params.type ? { shortcode: params.type } : false;
}

const { loading, error, refetch } = useQuery(getItemQuery, {
variables,
skip: !itemId,
fetchPolicy: getQueryFetchPolicy,
onCompleted: (data) => {
if (data) {
item = data[listItem] ? data[listItem][listItem] : data[Object.keys(data)[0]][listItem];
if (item) {
setIsLoadedData(true);
setLink(data[listItem] ? data[listItem][listItem][linkParameter] : item.linkParameter);
setLanguageId(languageSupport ? item.language.id : null);
if (setStates) {
setStates(item);
}
}
}
},
});

const camelCaseItem = listItem[0].toUpperCase() + listItem.slice(1);

const [updateItem] = useMutation(updateItemQuery, {
Expand Down Expand Up @@ -448,7 +447,6 @@ export const FormLayout = ({
afterSave(data, saveClick);
}
}
setIsLoadedData(true);
onSaveClick(false);
},
refetchQueries: () => {
Expand Down
35 changes: 14 additions & 21 deletions src/containers/HSM/HSM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,9 @@ export const HSM = () => {
setUploadedFile(null);
};

const [uploadMedia] = useMutation(UPLOAD_MEDIA, {
onCompleted: (data: { uploadMedia: string }) => {
setAttachmentURL(data.uploadMedia);
setNotification('File uploaded successfully');
setUploadingFile(false);
},
onError: (error: Error) => {
console.error('Upload error:', error);
setNotification('File upload failed. Please try again.');
resetUploadState();
},
});
const [uploadMedia] = useMutation(UPLOAD_MEDIA);

const handleFileUpload = (file: File): void => {
const handleFileUpload = async (file: File): Promise<void> => {
if (!file) return;

const mediaName = file.name;
Expand All @@ -156,12 +145,16 @@ export const HSM = () => {
setType({ id: 'DOCUMENT', label: 'DOCUMENT' });
}

uploadMedia({
variables: {
media: file,
extension,
},
});
try {
const result = await uploadMedia({ variables: { media: file, extension } });
setAttachmentURL(result.data.uploadMedia);
setNotification('File uploaded successfully');
setUploadingFile(false);
} catch (error) {
console.error('Upload error:', error);
setNotification('File upload failed. Please try again.', 'error');
resetUploadState();
}
};

let attachmentOptions = mediaOptions;
Expand Down Expand Up @@ -736,8 +729,8 @@ export const HSM = () => {
helperText: uploadedFile
? `File uploaded: ${uploadedFile.name}`
: t(
'Please provide a sample attachment for approval purpose. You may send a similar but different attachment when sending the HSM to users.'
),
'Please provide a sample attachment for approval purpose. You may send a similar but different attachment when sending the HSM to users.'
),
inputProp: {
onBlur: (event: any) => {
setAttachmentURL(event.target.value.trim());
Expand Down
25 changes: 12 additions & 13 deletions src/containers/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,6 @@ export const List = ({
// Make a new count request for a new count of the # of rows from this query in the back-end.
if (deleteItemQuery) {
[deleteItem] = useMutation(deleteItemQuery, {
onCompleted: () => {
setNotification(`${capitalListItemName} deleted successfully`);
checkUserRole();
countQuery && refetchCount();
if (refetchValues) {
refetchValues(filterPayload());
}
},
refetchQueries: () => {
if (refetchQueries)
return refetchQueries.map((refetchQuery: any) => ({
Expand All @@ -397,9 +389,6 @@ export const List = ({
}));
return [];
},
onError: () => {
setNotification(`Sorry! An error occurred!`, 'warning');
},
});
}

Expand All @@ -412,9 +401,19 @@ export const List = ({
setDeleteItemID(null);
};

const deleteHandler = (id: number) => {
const deleteHandler = async (id: number) => {
const variables = deleteModifier.variables ? deleteModifier.variables(id) : { id };
deleteItem({ variables });
try {
await deleteItem({ variables });
setNotification(`${capitalListItemName} deleted successfully`);
checkUserRole();
countQuery && refetchCount();
if (refetchValues) {
refetchValues(filterPayload());
}
} catch {
setNotification(`Sorry! An error occurred!`, 'warning');
}
};

const handleDeleteItem = () => {
Expand Down
Loading
Loading