Skip to content

Commit

Permalink
completed project deletion request
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakibul73 committed Oct 13, 2024
1 parent 27a0ecb commit 3768ae9
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 92 deletions.
26 changes: 26 additions & 0 deletions lib/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ class ApiService {
}
}

static Future<Map<String, dynamic>> handleProjectDeletionRequest(int notificationId) async {
final accessToken = await getAccessToken();
if (accessToken == null) {
throw Exception('JWT token not found');
}

final Uri url = Uri.parse('$baseUrl/delete_project_request/$notificationId');

try {
final http.Response response = await http.delete(
url,
headers: {
'Authorization': 'Bearer $accessToken',
'Accept-Encoding': 'gzip, deflate, br', // Specify the supported compression types
'Content-Type': 'application/json', // Specify the content type as JSON
},
);

final Map<String, dynamic> responseBody = jsonDecode(response.body);

return responseBody;
} catch (e) {
rethrow;
}
}

static Future<Map<String, dynamic>> updateNotice(Map<String, dynamic> updateNoticeData, int noticeID) async {
final accessToken = await getAccessToken();
if (accessToken == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2390,33 +2390,33 @@ class _EditProjectScreenAdminState extends State<EditProjectScreenAdmin> {
),
),
const Spacer(),
Visibility(
visible: widget.projectID.isNotEmpty,
child: Padding(
padding: const EdgeInsets.only(right: kDefaultPadding),
child: SizedBox(
height: 40.0,
child: ElevatedButton(
style: themeData.extension<AppButtonTheme>()!.errorElevated,
onPressed: () => _doDelete(context),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
child: Icon(
Icons.delete_rounded,
size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
),
),
const Text("Delete"),
],
),
),
),
),
),
// Visibility(
// visible: widget.projectID.isNotEmpty,
// child: Padding(
// padding: const EdgeInsets.only(right: kDefaultPadding),
// child: SizedBox(
// height: 40.0,
// child: ElevatedButton(
// style: themeData.extension<AppButtonTheme>()!.errorElevated,
// onPressed: () => _doDelete(context),
// child: Row(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Padding(
// padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
// child: Icon(
// Icons.delete_rounded,
// size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
// ),
// ),
// const Text("Delete"),
// ],
// ),
// ),
// ),
// ),
// ),
Visibility(
visible: widget.projectID.isNotEmpty,
child: Padding(
Expand Down
20 changes: 10 additions & 10 deletions lib/views/screens/admin/project_overview/SearchProjectScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class _SearchProjectScreenState extends State<SearchProjectScreen> {
_dataSource = DataSource(
onViewButtonPressed: (data) => GoRouter.of(context).go('${RouteUri.viewprojectadmin}?projectid=${data['ProjectID']}'),
onEditButtonPressed: (data) => GoRouter.of(context).go('${RouteUri.editprojectadmin}?projectid=${data['ProjectID']}'),
onDeleteButtonPressed: (data) {
deleteProject(data['ProjectID']);
},
// onDeleteButtonPressed: (data) {
// deleteProject(data['ProjectID']);
// },
data: [],
);
}
Expand Down Expand Up @@ -345,13 +345,13 @@ class _SearchProjectScreenState extends State<SearchProjectScreen> {
class DataSource extends DataTableSource {
final void Function(Map<String, dynamic> data) onEditButtonPressed;
final void Function(Map<String, dynamic> data) onViewButtonPressed;
final void Function(Map<String, dynamic> data) onDeleteButtonPressed;
// final void Function(Map<String, dynamic> data) onDeleteButtonPressed;
List<dynamic> data;

DataSource({
required this.onEditButtonPressed,
required this.onViewButtonPressed,
required this.onDeleteButtonPressed,
// required this.onDeleteButtonPressed,
required this.data,
});

Expand Down Expand Up @@ -390,11 +390,11 @@ class DataSource extends DataTableSource {
child: const Text("Edit"),
),
),
OutlinedButton(
onPressed: () => onDeleteButtonPressed.call(data),
style: Theme.of(context).extension<AppButtonTheme>()!.errorOutlined,
child: const Text("Delete"),
),
// OutlinedButton(
// onPressed: () => onDeleteButtonPressed.call(data),
// style: Theme.of(context).extension<AppButtonTheme>()!.errorOutlined,
// child: const Text("Delete"),
// ),
],
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3068,33 +3068,33 @@ class _ViewProjectScreenAdminState extends State<ViewProjectScreenAdmin> {
),
),
),
Visibility(
visible: widget.projectID.isNotEmpty,
child: Padding(
padding: const EdgeInsets.only(right: kDefaultPadding),
child: SizedBox(
height: 40.0,
child: ElevatedButton(
style: themeData.extension<AppButtonTheme>()!.infoOutlined,
onPressed: () => _goEditPage(context),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
child: Icon(
Icons.mode_edit_outline_outlined,
size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
),
),
const Text("Edit Project"),
],
),
),
),
),
)
// Visibility(
// visible: widget.projectID.isNotEmpty,
// child: Padding(
// padding: const EdgeInsets.only(right: kDefaultPadding),
// child: SizedBox(
// height: 40.0,
// child: ElevatedButton(
// style: themeData.extension<AppButtonTheme>()!.infoOutlined,
// onPressed: () => _goEditPage(context),
// child: Row(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Padding(
// padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
// child: Icon(
// Icons.mode_edit_outline_outlined,
// size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
// ),
// ),
// const Text("Edit Project"),
// ],
// ),
// ),
// ),
// ),
// )
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,78 @@ class _ViewIndividualNotificationScreenState extends State<ViewIndividualNotific
_formData.receiverUserID = userDetails['Notification']['ReceiverUserID'].toString();
_formData.senderUserID = userDetails['Notification']['SenderUserID'].toString();
_formData.timestamp = userDetails['Notification']['Timestamp'];
// if IsDeleted = 0 , then this project deletion request is not yet done
_formData.isDeleted = userDetails['Notification']['IsDeleted'] ?? 0;
});
}

return true;
}

Future<void> _handleProjectDeletionRequest(BuildContext context) async {
// Extract project ID from the message
int notificationId = int.parse(widget.notificationID);

// Call the API service to handle the project deletion request
final result = await ApiService.handleProjectDeletionRequest(notificationId);

if (result['statuscode'] == 401) {
// Handle token expiration
final dialog = AwesomeDialog(
context: context,
dialogType: DialogType.error,
desc: "Token expired. Please login again.",
width: kDialogWidth,
btnOkText: 'OK',
btnOkOnPress: () {
GoRouter.of(context).go(RouteUri.logout);
},
);
dialog.show();
}
if (result['statuscode'] == 404) {
// Handle token expiration
final dialog = AwesomeDialog(
context: context,
dialogType: DialogType.error,
desc: result['error'],
width: kDialogWidth,
btnOkText: 'OK',
btnOkOnPress: () {
GoRouter.of(context).go(RouteUri.viewallnotifications);
},
);
dialog.show();
}
if (result['statuscode'] == 500) {
// Handle token expiration
final dialog = AwesomeDialog(
context: context,
dialogType: DialogType.error,
desc: result['error'],
width: kDialogWidth,
btnOkText: 'OK',
btnOkOnPress: () {
GoRouter.of(context).go(RouteUri.viewallnotifications);
},
);
dialog.show();
}
if (result['statuscode'] == 200) {
final dialog = AwesomeDialog(
context: context,
dialogType: DialogType.success,
desc: result['message'],
width: kDialogWidth,
btnOkText: 'OK',
btnOkOnPress: () {
GoRouter.of(context).go(RouteUri.viewallnotifications);
},
);
dialog.show();
}
}

@override
Widget build(BuildContext context) {
final themeData = Theme.of(context);
Expand Down Expand Up @@ -279,34 +345,65 @@ class _ViewIndividualNotificationScreenState extends State<ViewIndividualNotific
),
),
),
// const Spacer(),
// Visibility(
// visible: initialPendingUserDataChange,
// child: Padding(
// padding: const EdgeInsets.only(right: kDefaultPadding),
// child: SizedBox(
// height: 40.0,
// child: ElevatedButton(
// style: themeData.extension<AppButtonTheme>()!.successOutlined,
// onPressed: () => _goSaveChanges(context),
// child: Row(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Padding(
// padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
// child: Icon(
// Icons.save_outlined,
// size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
// ),
// ),
// const Text("Save Changes"),
// ],
// ),
// ),
// ),
// ),
// ),
const Spacer(),
Visibility(
// if IsDeleted = 0 , then this project deletion request is not yet done
visible: _formData.message.startsWith('ProjectDeletionRequest') && _formData.isDeleted == 1,
child: Padding(
padding: const EdgeInsets.only(right: kDefaultPadding),
child: SizedBox(
height: 40.0,
child: Tooltip(
message: 'Already Deleted',
child: ElevatedButton(
style: themeData.extension<AppButtonTheme>()!.errorOutlined,
onPressed: null,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
child: Icon(
Icons.delete_outline_outlined,
size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
),
),
const Text("Delete Requested Project"),
],
),
),
)),
),
),
Visibility(
// if IsDeleted = 0 , then this project deletion request is not yet done
visible: _formData.message.startsWith('ProjectDeletionRequest') && _formData.isDeleted == 0,
child: Padding(
padding: const EdgeInsets.only(right: kDefaultPadding),
child: SizedBox(
height: 40.0,
child: ElevatedButton(
style: themeData.extension<AppButtonTheme>()!.errorOutlined,
onPressed: () => _handleProjectDeletionRequest(context),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(right: kDefaultPadding * 0.5),
child: Icon(
Icons.delete_outline_outlined,
size: (themeData.textTheme.labelLarge!.fontSize! + 4.0),
),
),
const Text("Delete Requested Project"),
],
),
),
),
),
),
// Visibility(
// visible: widget.notificationID.isNotEmpty,
// child: Padding(
Expand Down Expand Up @@ -357,4 +454,5 @@ class FormData {
String message = '';
String timestamp = '';
String isRead = '';
int isDeleted = 0;
}

0 comments on commit 3768ae9

Please sign in to comment.